Ask Your Question

gcc does not find c++ headers

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

cherio gravatar image

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


    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


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

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


This bit me in 2002

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

3 Answers

Sort by » oldest newest most voted

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

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

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


@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 -0500 )edit

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

florian gravatar image

Install gcc-c++

edit flag offensive delete link more

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

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



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

alfC gravatar imagealfC ( 2018-05-26 01:36:06 -0500 )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


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

Seen: 145 times

Last updated: May 24 '18