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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Console app not compiling 2

Status
Not open for further replies.

SQL2KDBA69

Programmer
Feb 4, 2004
227
0
0
US
here is my code

#include <iostream.h>

int main()
{

cout << "Hello World";
return 0;

}


I cant get the cout command to work. I using VS 2005 Pro edition.

:
 
i tried it like this :
#include <stdafx.h>

int main()
{

cout << "Hello World";
return 0;

}

and i get cout is undefined.
 
Well probably because your compiler supports the new C++ standard.
Code:
#include <iostream>  // note - there is no .h
using namespace std; // this is new
int main ( ) {
  cout << "hello world" << endl;  // one way
  std::cout << "hello world" << endl;  // another way
  return 0;
}

Please use the [tt][ignore]
Code:
[/ignore][/tt]
tags when posting code.

--
 
tried that and it ask if i forgot to put #include "stdafx.h" in my code.
 
also saying "unexpected end of file while looking for precompile header.
 
Go into the Project settings and choose not to use Precompiled headers. They're more trouble than they're worth.
Otherwise, create an empty stdafx.h file (you don't need anything in it), then include it before any other #include statements.
 
did that and it say :

cout is an undefined indentifier
 
You need to also put
Code:
using namespace std;
after your #include lines.
 
#include "stdafx.h"

using namespace std;

int main()
{
cout << "Hello World";
return 0;
}


tried that and i get :

'std' a namespace with this name does not exist.
 
The following should work fine if you open an EMPTY project, then add this as a CPP file.

Code:
#include <iostream.h>
using namespace std;
int main()
{

cout << "Hello World";
return 0;

}

Lee
 
Tried that and here is the errors :

Error 1 error C2871: 'std' : a namespace with this name does not exist
Error 2 error C2065: 'cout' : undeclared identifier


I create an empty project and created a cpp file and a header file then tried to compile it and got those error.

and just a reminder im using Visual C++ in Visual Studio 2005 Professional Editon with .Net 2.0
 
My error. Should be without the .h. The old style header files used the .h extension. You shouldn't need a header file for this simple of a project.

Code:
#include <iostream>
using namespace std;
int main()
{

cout << "Hello World";
return 0;

}

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top