Error on compiling

I keep getting an error when I use this code:
1
2
3
4
5
#include <iostream>
main() {
cout << "Hello World!";
return 0;
}

and this is the error:
1
2
3
4
5
6
Compiling: C:\Users\Rex\Desktop\Test.cpp
C:\Users\Rex\Desktop\Test.cpp: In function 'int main()':
C:\Users\Rex\Desktop\Test.cpp:3: error: 'cout' was not declared in this scope
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
 

If anyone could help that would be awesome.
i think you need int main ()

i think you need using namespace std;

or cout std::some code after.(some old way of coding... its not correct so use using namespace...)

#include .....

using namespace std;

int main()
{
code blah blah blah;

system("pause"); //to stop the screen to view what you created.
return 0;
}
Last edited on
cout lives in the std namespace. Your options are as follows:

using namespace std;

using std::cout;

std::cout << "Hello World!";


As Nick says, use

int main()

rather than

main()

Topic archived. No new replies allowed.