Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 681
Wallter Avatar asked Dec 08 '09 17:12

Wallter


People also ask

What is undeclared identifier in C++?

The identifier is undeclared: In any programming language, all variables have to be declared before they are used. If you try to use the name of a such that hasn't been declared yet, an “undeclared identifier” compile-error will occur. Example: #include <stdio.h> int main()

Is cout an identifier?

Standard identifiers have a special meaning in C++. They are the names of operations defined in the standard C++ library. For example: cout is the name of an I/O operation. Unlike reserved words, standard identifiers can be redefined and used by the programmer for other purposes.


1 Answers

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

These will not work.

#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; } 

This will do.

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

Here is a great answer on what the stdafx.h header does.

like image 62
George Chondrompilas Avatar answered Sep 20 '22 03:09

George Chondrompilas