error C2065: 'cout' : undeclared identifier


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

error C2065: 'cout' : undeclared identifier

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;

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

2/7/2013 4:02:21 PM

write this code, it works perfectly..

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

using namespace std;

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

I had same problem on Visual Studio C++ 2010. It's easy to fix. Above the main() function just replace the standard include lines with this below but with the pound symbol in front of the includes.

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

The include "stdafx.h" is ok

But you can't use cout unless you have included using namespace std

If you have not included namespace std you have to write std::cout instead of simple cout


I have seen that if you use

#include <iostream.h>

then you will get the problem.

If you use

#include <iostream>  

(notice - without the .h)

then you will not get the problem you mentioned.


If you started a project requiring the #include "stdafx.h" line, put it first.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]