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.
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()
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With