I am working on the \'driver\' part of my programing assignment and i keep getting this absurd error:
error C2065: \'cout\' : undeclared identifier
If you started a project requiring the #include "stdafx.h"
line, put it first.
Just use printf
!
Include stdio.h
in your stdafx.h
header file for printf
.
When you created your project, you did not set 'use precompiled headers' correctly. Change it in properties->C/C++->precompiled headers.
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?)
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;
Such a silly solution in my case:
// Example a
#include <iostream>
#include "stdafx.h"
The above was odered as per example a, when I changed it to resemble example b below...
// Example b
#include "stdafx.h"
#include <iostream>
My code compiled like a charm. Try it, guaranteed to work.