Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cout/namespace issue

Status
Not open for further replies.

UltimateMaster50

Programmer
Feb 9, 2009
3
US
I'm having trouble getting a pretty simple C++ program to compile, and I'm not sure why... >_< Here's what I have:

Code:
#include <iostream>
using namespace std;
#include "stdafx.h"

int main()
{
	cout<<"Please work!!!!";
	return 0;
}

and I'm getting:
error C2653: 'std' : is not a class or namespace name
error C2065: 'cout' : undeclared identifier

I really can't figure out what I'm doing wrong! Any help would be greatly appreciated!
 
Edit: Actually, the first error I listed was from an old build - I'm just getting the error about the cout.
 
1. delete the stdafx.h include line.
2. In project settings -> compiler -> pre-processor (or similar), turn OFF pre-compiled headers.


--
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
 
Better don't delete stdafx.h (if you have VC++), place #include <iostream> in the stdafx.h and move using namespace std after #include "stdafx.h":
Code:
// VC++ ignores all lines before #include "stdafx.h"
// in "using pre-compiled headers" mode 
// (it's a new project default).
#include "stdafx.h"
using namespace std;

int main()
{
    cout << "Please read VC++ manuals or help pages!!!!";
    return 0;
}
// stdafx.h:
... VC++ generated stuff
#include <iostream>
// TODO: reference additional headers your program requires here
Have you ever seen stdafx.h file content?
Look for pre-compiled headers in VC++ MSDN...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top