cppaddict wrote:
I'm getting an compile error (using cygwin gcc on windows xp) when I
try to compile the following simple program:
#include <iostream>
int main(void) {
cout << "C++ Hello World";
return 0;
}
It says that cout is undefined. Adding the line "using namespace
std;" after the include doesn't fix the problem. Anyone know what's
going on and how I can fix it?
cout is in the std namespace, so you do need to indicate the namespace
("using namespace std;" is one way).
Other than that, there's nothing wrong with the code (except technically
you should also #include <ostream>, though with most compilers it isn't
necessary). My guess is that you're getting a linker error because you
built the program like this:
gcc hello.cpp
instead of like this:
g++ hello.cpp
BTW, I would also recommend you use the flags "-ansi -pedantic -W
-Wall," if you aren't already.
--
Russell Hanneken
rg********@pobox.com
Remove the 'g' from my address to send me mail.