2

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...

Everett
  • 1,077
  • 5
  • 23
  • 42

4 Answers4

17

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
  • 97,545
  • 26
  • 194
  • 236
6

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
3

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
  • 8,356
  • 19
  • 50
  • 61
0

use

#include<iostream>
using namespace std;

without namespace you won't be able to use cout or cin

kumar
  • 11