Link to home
Start Free TrialLog in
Avatar of Ryan94114
Ryan94114

asked on

Why does Visual Studio seem to ignore my include file directives?

I'm getting an error in Visual Studio on something that should be very simple.

In the following code, cout is flagged as undefined when I attempt to compile.

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

int _tmain(int argc, _TCHAR* argv[])
{
	cout << "Hello World\n";
	return 0;
}

Open in new window


I tried <iostream.h>, I tried putting the include in stdafx.h, all to no avail.  The compiler keeps telling me that cout is undefined; if I press f12 while selecting cout, it tells me the symbol is defined in iostream.h.  But intellisense says cout is undefined and the compiler gives an error indicating cout is undefined.

This is inside a WIN32 Console application. The source code above is the complete contents of test.cpp.

The error message is:
Error      2      error C2065: 'cout' : undeclared identifier
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
either add: just below the includes
using namespace std;

Open in new window


or on ever occurrence of cout use:
std::cout

Open in new window