错误 C2065: 'cout' : 未声明的标识符

20 浏览
0 Comments

错误 C2065: 'cout' : 未声明的标识符

我正在处理我的编程任务中的\"驱动\"部分,但我一直遇到这个荒谬的错误:

错误 C2065:\'cout\':未声明的标识符

我甚至尝试使用std::cout,但我又得到了另一个错误,它说:

IntelliSense:命名空间 \"std\" 没有成员 \"cout\"

当我已经声明了using namespace std, included iostream,甚至尝试使用ostream

#include 
using namespace std;
int main () {
    cout << "hey" << endl;
 return 0;
}

我正在使用Visual Studio 2010并运行Windows 7。所有的.h文件都有using namespace std和包括iostreamostream

admin 更改状态以发布 2023年5月22日
0
0 Comments

把这段代码写出来,它可以完美地工作。

#include "stdafx.h"
#include 
using namespace std;
int main()
{
 cout<<"Hello World!";
  return 0;
}

0
0 Comments

在Visual Studio中,您必须#include "stdafx.h"并且是cpp文件的第一个包含。例如:

下面的内容不会起作用。

#include 
using namespace std;
int main () {
    cout << "hey" << endl;
    return 0;
}
#include 
#include "stdafx.h"
using namespace std;
int main () {
    cout << "hey" << endl;
    return 0;
}

这个可以。

#include "stdafx.h"
#include 
using namespace std;
int main () {
    cout << "hey" << endl;
    return 0;
}

这里是有关stdafx.h头文件的一个很好的答案。

0