要规定命名空间(std),使用:
#include <iostream>
using namespace std;
或者是在需要专有命名空间的函数前面加上std::
std::cout
不然就会报错:
tmp.cpp:3:5: error: use of undeclared identifier 'cout'; did you mean 'std::cout'?
cout << "HelloWorld!" << endl;
^~~~
std::cout
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:54:33: note: 'std::cout' declared here
extern _LIBCPP_FUNC_VIS ostream cout;
^
tmp.cpp:3:30: error: use of undeclared identifier 'endl'; did you mean 'std::endl'?
cout << "HelloWorld!" << endl;
^~~~
std::endl
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ostream:1001:1: note: 'std::endl' declared here
endl(basic_ostream<_CharT, _Traits>& __os)
^
2 errors generated.