Ask Your Question
0

gcc does not find c++ headers

asked 2018-05-24 11:44:05 -0600

cherio gravatar image

The latest installation of gcc does not compile c++ programs

#include<iostream.h>

    int main() {
      cout << "This is test\n";
     return 0;
    }

results in fatal error: <iostream.h> no such file or directory However in /usr/include/c++/7 there is a iostream file, so I tried this

#include<iostream>

  int main() {
  cout << "This is test\n";
 return 0;
}

which results in,

 ostreamtest.cc: In function ‘int main()’:
test.cc:5:4: error: ‘cout’ was not declared in this scope
    cout << "This is a test\n";
    ^~~~
test.cc:5:4: note: suggested alternative:
In file included from test.cc:1:0:
/usr/include/c++/7/iostream:61:18: note:   ‘std::cout’
   exte cout;  /// Linked to standard output
                  ^~~~
edit retag flag offensive close merge delete

Comments

This bit me in 2002

alfC gravatar imagealfC ( 2018-05-25 00:57:57 -0600 )edit

3 Answers

Sort by » oldest newest most voted
3

answered 2018-05-24 13:06:01 -0600

updated 2018-05-24 13:08:24 -0600

As the error from the last output already outlines, use std::cout instead of cout and install and use gcc-c++.

[user@localhost test]$ cat test.cpp
#include <iostream>

int main() {
    std::cout << "This is test\n";
    return 0;
}
[user@localhost test]$ g++ test.cpp -o test
[user@localhost test]$ ./test
This is test
edit flag offensive delete link more

Comments

@thomaswood, you'll be able to just say cout as opposed to std::cout without anything additional. You can get the same behavior in standard C++ by adding using std::cout; or using namespace std; after #include

hhlp gravatar imagehhlp ( 2018-05-25 04:05:45 -0600 )edit
2

answered 2018-05-24 12:22:59 -0600

florian gravatar image

Install gcc-c++

edit flag offensive delete link more
0

answered 2018-05-25 02:33:07 -0600

cherio gravatar image

Thank you for updating me. Fairly familiar, but not used C++ much. On Turbo C++ worked fine, so I was a bit puzzled. Is this gcc-c++ a different package or the same as g++ which is already present in my system anyway ?

edit flag offensive delete link more

Comments

1

Turbo C++ is(was) a pre-standard compiler. A few things changed since then.

alfC gravatar imagealfC ( 2018-05-26 01:36:06 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-05-24 11:40:33 -0600

Seen: 86 times

Last updated: May 24