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

error C2065: #39;cout#39; : undeclared identifier(错误 C2065:“cout:未声明的标识符)

本文介绍了错误 C2065:“cout":未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理我的编程任务的驱动程序"部分,但我不断收到这个荒谬的错误:

I am working on the 'driver' part of my programing assignment and i keep getting this absurd error:

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

error C2065: 'cout' : undeclared identifier

我什至尝试过使用 std::cout 但我收到另一个错误消息:IntelliSense: namespace "std" has no member "cout" 当我有声明 using namespace std,包括 iostream + 我什至尝试使用 ostream

I have even tried using the std::cout but i get another error that says: IntelliSense: namespace "std" has no member "cout" when i have declared using namespace std, included iostream + i even tried to use ostream

我知道这是一个标准的菜鸟问题,但这让我很难过,而且我是个新手(意思是:我以前编程过......)

I know it's a standard noob question but this has stumped me and I'm a novice (meaning: I've programed before...)

#include <iostream>
using namespace std;

int main () {
    cout << "hey" << endl;
 return 0;
}

我使用的是 Visual Studio 2010 并运行 Windows 7.所有 .h 文件都有使用命名空间 std"并包括 iostream 和 ostream.

I'm using Visual Studio 2010 and running Windows 7. All of the .h files have "using namespace std" and include iostream and ostream.

推荐答案

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

In Visual Studio you must #include "stdafx.h" and be the first include of the cpp file. For instance:

这些不起作用.

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




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

这就行了.

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

这里有一个关于 stdafx.h 标头功能的很好的答案.

这篇关于错误 C2065:“cout":未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:错误 C2065:“cout":未声明的标识符

基础教程推荐