views:

999

answers:

3

I just installed Ubuntu and tried making the famed "Hello World" program to make sure that all the basics were working. For some reason though, g++ fails to compile my program with the error: "'cout' is not a member of 'std'". I've installed the build-essential package. Am I missing something else?

#include <iostream.h>

int main() {
   std::cout << "Hello World!" << std::endl;
   return 0;
}

Looks pretty good to me...

+11  A: 

Use #include <iostream> - iostream.h is not standard and may differ from the standard behaviour.

See e.g. the C++ FAQ lite entry on the matter.

Georg Fritzsche
+5  A: 

The standard header is called <iostream>, not <iostream.h>. Also, it is agood idea to compile your C++code with the -Wall and -pedantic flags, which can point out lots of errors with non-standard code that g++ would otherwise ignore. Use:

g++ -Wall -pedantic myprog.cpp
anon
+2  A: 

Sounds like it did find iostream.h but it does not define cout in the std namespace. It is there for backwards compatibility with older programs that expect cout to be in the global namespace.

Kevin Panko