'cout'没有在这个范围内宣布
我有一个C ++程序:
#include<iostream> int main() { char t = 'f'; char *t1; char **t2; cout<<t; //this causes an error, cout was not declared in this scope return 0; } g ++ test.cpp
 我得到错误error: 'cout' was not declared in this scope 
为什么?
 把下面的代码放在int main()之前: 
 using namespace std; 
 你将可以使用cout 。 
例如:
 #include<iostream> using namespace std; int main(){ char t = 'f'; char *t1; char **t2; cout<<t; return 0; } 
现在花点时间阅读一下cout是什么以及发生了什么: http : //www.cplusplus.com/reference/iostream/cout/
 使用std::cout ,因为cout是在std命名空间中定义的。 或者,添加一个using std::cout; 指示。