C++ cout 给出了未声明的标识符

21 浏览
0 Comments

C++ cout 给出了未声明的标识符

所以,我有一个问题。为什么 cout 抛出

error C2065: 'cout' : undeclared identifier

? 我正在使用 Visual Studio 2012 作为 IDE,写一个学校项目。我已经完成了所有东西,除了一个示例文件。所以我想在屏幕上写一些东西,像这样:

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

。所以问题出在 cout 上,printf 能正常工作,但我想使用 cout。 编辑:我已经将\"\"更改为<>,但仍然没有帮助。此外,我仅使用此代码作为示例...这不是整个项目。

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

首先:

#include 

要用#include "iostream"代替。

其次,尽管大多数课程都以这种方式开始,但一般认为编写using namespace std;是不好的实践。最好只使用你实际需要的,比如在你的情况下:

using std::cout;

0
0 Comments

stdafx.h 应该是你的源文件中第一个包含指令。

将文件切换并将第二个包含指令转换为<>,正如其他人建议的那样。

#include "stdafx.h"
#include 

有关更多信息,请参见此帖子

0