我有一个C++程序:
test.cpp
#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;
}
我收到了以下错误信息: “cout在此范围内未声明” 为什么会出现这个错误?
我有一个C++程序:
test.cpp
#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;
}
在int main()
之前放置以下代码:
using namespace std;
你将能够使用cout
。
例如:
#include<iostream>
using namespace std;
int main(){
char t = 'f';
char *t1;
char **t2;
cout<<t;
return 0;
}
using namespace std;
并不是一个好的建议。如需详细正确的方法,请阅读相关的SO问题的答案。std
的不良建议的文章。 - juanchopanzastd::cout
,因为 cout
在 std
命名空间中定义。或者,添加一个 using std::cout;
指令。