Advertisement
Advertisement


error C2065: 'cout' : undeclared identifier


Question

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.

2013/02/07
1
70
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;
2011/07/04

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

2014/11/18

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.

2010/11/14

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

2012/01/13

Source: https://stackoverflow.com/questions/1868603
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]