1

I have a hello world C++ file including standard <iostream> header. System is Ubuntu 14.04

Program is:

#include <iostream>
using namespace std;

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

building this with g++:

g++ main.cpp -o main

gives:

In file included from main.cpp:1:0:
/usr/include/c++/4.8/iostream:61:18: note:   ‘std::cout’
extern ostream cout;  /// Linked to standard output
              ^
main.cpp:6:13: error: ‘endl’ was not declared in this scope
cout << endl;
         ^
main.cpp:6:13: note: suggested alternative:
In file included from /usr/include/c++/4.8/iostream:39:0,
             from main.cpp:1:
/usr/include/c++/4.8/ostream:564:5: note:   ‘std::endl’
endl(basic_ostream<_CharT, _Traits>& __os)
 ^
hello.cpp: In function ‘void print_hello()’:
hello.cpp:5:4: error: ‘cout’ was not declared in this scope
cout << "Hello World!";
^
hello.cpp:5:4: note: suggested alternative:
In file included from hello.cpp:1:0:
/usr/include/c++/4.8/iostream:61:18: note:   ‘std::cout’
extern ostream cout;  /// Linked to standard output

Do I need to configure path to standard libraries somewhere?

EDIT

I changed <iostream.h> to <iostream> but problem remains in another form.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
doubleE
  • 1,027
  • 1
  • 12
  • 32
  • 8
    `#include ` if you saw this in a tutorial, stop reading it and find a new one. – Borgleader Feb 02 '16 at 20:57
  • I changed that but gives other errors. Please see edited question. – doubleE Feb 02 '16 at 21:19
  • New problem, new question. Please revert your edit to the previous version so that the closing reason makes sense, then make a new question. – user4581301 Feb 02 '16 at 21:34
  • But odds are good that new question will be closed: Unable to reproduce. – user4581301 Feb 02 '16 at 21:36
  • now a duplicate of http://stackoverflow.com/questions/15359589/cout-is-not-a-member-of-std-cout-was-not-declared-in-this-scope that is the 5th in Google on "‘endl’ was not declared in this scope". – ivan_pozdeev Feb 02 '16 at 22:03

0 Answers0