Program Tip

오류 C2065 : 'cout': 선언되지 않은 식별자

programtip 2020. 11. 13. 23:55
반응형

오류 C2065 : 'cout': 선언되지 않은 식별자


나는 내 프로그래밍 과제의 '드라이버'부분을 작업 중이며이 터무니없는 오류가 계속 발생합니다.

오류 C2065 : 'cout': 선언되지 않은 식별자

std :: cout을 사용해 보았지만 다음과 같은 또 다른 오류가 발생합니다. IntelliSense : namespace "std"에는 네임 스페이스 std를 사용하여 선언 할 때 "cout"멤버가 없습니다. iostream 포함 + 심지어 ostream 을 사용하려고했습니다.

나는 그것이 표준 멍청한 질문이라는 것을 알고 있지만 이것은 나를 괴롭 혔고 나는 초보자입니다 (의미 : 나는 전에 프로그래밍했습니다 ...)

#include <iostream>
using namespace std;

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

저는 Visual Studio 2010을 사용하고 있고 Windows 7을 실행하고 있습니다. 모든 .h 파일에는 "using namespace std"가 있으며 iostream 및 ostream이 포함됩니다.


Visual Studio에서 다음을 수행해야 #include "stdafx.h"(가) 먼저 CPP 파일의 포함한다. 예를 들면 :

이들은됩니다 없습니다 작동합니다.

#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 헤더가하는 일에 대한 훌륭한 답변입니다.


이 코드를 작성하면 완벽하게 작동합니다 ..

#include "stdafx.h"
#include <iostream>

using namespace std;

int main()
{
 cout<<"Hello World!";
  return 0;
}

Visual Studio C ++ 2010에서 동일한 문제가 발생했습니다. 쉽게 수정할 수 있습니다. main () 함수 위에는 표준 include 행을 아래로 바꾸고 include 앞에 파운드 기호를 넣으십시오.

# include "stdafx.h"
# include <iostream>
using  namespace std;

include "stdafx.h"괜찮습니다

하지만 cout포함하지 않으면 사용할 수 없습니다using namespace std

네임 스페이스 std를 포함하지 않은 경우 std::cout간단한 대신 작성해야합니다.cout


나는 당신이 사용한다면

#include <iostream.h>

그러면 문제가 생깁니다.

사용하는 경우

#include <iostream>  

(알림-.h 제외)

그러면 언급 한 문제를 얻지 못할 것입니다.


#include "stdafx.h"라인이 필요한 프로젝트를 시작한 경우 먼저 입력하십시오.


아래 코드는 gcc를 사용하여 제대로 컴파일되고 실행됩니다. 이것을 복사 / 붙여 넣기하고 작동하는지 확인하십시오.

#include <iostream>
using namespace std;

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

int main () {
    int a = 1;
    bob(a);
    return 0;
}

포함하는 유일한 파일이 iostream이고 여전히 undefined라고 표시되는 경우 iostream에 예상되는 내용이 포함되어 있지 않을 수 있습니다. 프로젝트에 "iostream"이라는 이름의 빈 파일이있을 가능성이 있습니까?


C ++ 코드에서 .c 파일 확장자를 사용할 때 비슷한 일이 발생하는 것을 보았습니다. 그 외에는 버그가있는 설치에 대해 모든 사람과 동의해야합니다. VS의 이전 릴리스로 프로젝트를 컴파일하려고하면 작동합니까? VC ++ Express 2008을 사용해보십시오. msdn에서 무료입니다.


제 경우에는 그런 어리석은 해결책 :

// Example a
#include <iostream>    
#include "stdafx.h"

위의 예는 아래 예 b와 비슷하게 변경했을 때 예 a에 따라 odered되었습니다.

// Example b
#include "stdafx.h"
#include <iostream>  

My code compiled like a charm. Try it, guaranteed to work.


I have VS2010, Beta 1 and Beta 2 (one on my work machine and one at home), and I've used std plenty without issues. Try typing:

std::

And see if Intellisense gives you anything. If it gives you the usual stuff (abort, abs, acos, etc.), except for cout, well then, that is quite a puzzler. Definitely look into your C++ headers in that case.

Beyond that, I would just add to make sure you're running a regular, empty project (not CLR, where Intellisense is crippled), and that you've actually attempted to build the project at least once. As I mentioned in a comment, VS2010 parses files once you've added an include; it could be that something stuck the parser and it didn't "find" cout right away. (In which case, try restarting VS maybe?)


Take the code

#include <iostream>
using namespace std;

out of your .cpp file, create a header file and put this in the .h file. Then add

#include "whatever your header file is named.h"

at the top of your .cpp code. Then run it again.


I had the same issue when starting a ms c++ 2010 project from scratch - I removed all of the header files generated by ms and but used:

#include "stdafx.h"
#include <iostream>
using namespace std;

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

I had to include stdafx.h as it caused an error not having it in.


before you begin this program get rid of all the code and do a simple hello world inside of main. Only include iostream and using namespace std;. Little by little add to it to find your issue.

cout << "hi" << endl;

Are you sure it's compiling as C++? Check your file name (it should end in .cpp). Check your project settings.

There's simply nothing wrong with your program, and cout is in namespace std. Your installation of VS 2010 Beta 2 is defective, and I don't think it's just your installation.

I don't think VS 2010 is ready for C++ yet. The standard "Hello, World" program didn't work on Beta 1. I just tried creating a test Win32 console application, and the generated test.cpp file didn't have a main() function.

I've got a really, really bad feeling about VS 2010.


Try it, it will work. I checked it in Windows XP, Visual Studio 2010 Express.

#include "stdafx.h"
#include <iostream>
using namespace std;

void main( ) 
{
   int i = 0;
   cout << "Enter a number: ";
   cin >> i;
}

When you created your project, you did not set 'use precompiled headers' correctly. Change it in properties->C/C++->precompiled headers.


In Visual studio use all your header filer below "stdafx.h".


Include the std library by inserting the following line at the top of your code:

using namespace std;

is normally stored in the C:\Program Files\Microsoft Visual Studio 8\VC\include folder. First check if it is still there. Then choose Tools + Options, Projects and Solutions, VC++ Directories, choose "Include files" in the "Show Directories for" combobox and double-check that $(VCInstallDir)include is on top of the list.


I ran across this error after just having installed vs 2010 and just trying to get a nearly identical program to work.

I've done vanilla C coding on unix-style boxes before, decided I'd play with this a bit myself.

The first program I tried was:

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    cout << "Hello World!";
    return 0;
}

The big thing to notice here... if you've EVER done any C coding,

int _tmain(int argc, _TCHAR* argv[])

Looks weird. it should be:

int main( int argc, char ** argv )

In my case I just changed the program to:

#include <iostream>
using namespace std;

int main()
{
     cout << "Hello world from  VS 2010!\n";
     return 0;
}

And it worked fine.

Note: Use CTRL + F5 so that the console window sticks around so you can see the results.


Just use printf!

Include stdio.h in your stdafx.h header file for printf.


I came here because I had the same problem, but when I did #include "stdafx.h" it said it did not find that file.
What did the trick for me was: #include <algorithm>.
I use Microsoft Visual Studio 2008.
These are the things that you can use then, incl. 'count': Link



It was the compiler - I'm now using Eclipse Galileo and the program works like a wonder


참고URL : https://stackoverflow.com/questions/1868603/error-c2065-cout-undeclared-identifier

반응형