如果没有使用using namespace std;,则在使用标准库的函数、类、对象时,需要加上std::来指明命名空间。例如,如果要使用coutendl,需要写成std::coutstd::endl

示例代码如下:

#include <iostream>

int main() {
  std::cout << "Hello, world!" << std::endl;
  return 0;
}

如果不加std::,编译器会报错,提示找不到相应的标识符。加上using namespace std;可以避免每次都要加上std::的繁琐写法。但是在大型项目中,为了避免命名冲突,一般不建议在头文件中使用using namespace std;,而是在具体的源文件中使用。

c++中如果没有using namespace std;会怎么样

原文地址: https://www.cveoy.top/t/topic/ifRl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录