You can get the error
‘cout’ was not declared in this scope
if you forget to include iostream or to use the std namespace.
WRONG
#include <iostream> // no using namespace std;
int main(void)
{
cout << "A";
return 0;
}
ALSO WRONG
using namespace std; // no #include iostream
int main(void)
{
cout << "A";
return 0;
}
RIGHT
#include <iostream> // one of two
using namespace std; // two of two, yay!
int main(void)
{
cout << "A";
return 0;
}
‘cout’ was not declared in this scope
You can get the error
‘cout’ was not declared in this scope
if you forget to include iostream or to use the std namespace.
WRONG
#include <iostream> // no using namespace std;
int main(void)
{
cout << "A";
return 0;
}
ALSO WRONG
using namespace std; // no #include iostream
int main(void)
{
cout << "A";
return 0;
}
RIGHT
#include <iostream> // one of two
using namespace std; // two of two, yay!
int main(void)
{
cout << "A";
return 0;
}

当遇到'cout' was not declared in this scope的错误,通常是因为忘记包含<iostream>头文件或没有使用std命名空间。正确的做法是同时包含头文件并使用命名空间。
2万+

被折叠的 条评论
为什么被折叠?



