Thread: gcc compiler can not find header file

  1. #1
    Registered User
    Join Date
    Jun 2017
    Posts
    4

    gcc compiler can not find header file

    There must be a very simple book for beginners but could not locate it.

    I try :
    Code:
    
    
    Code:
    #include "iostream.h"
      int main() 
      {
        cout << "Hello\n";
      } 
    


    and get errors about header file. I am using Ubuntu 17.04 and gcc is 6.3.0


    TIA


    Regards

  2. #2
    Registered User
    Join Date
    Jun 2017
    Posts
    1
    Replace
    Code:
    #include "iostream.h"
    with
    Code:
    #include <iostream>
    . Then put
    Code:
    using namespace std;
    at the top of main(). This should probably be in the C++ board, though.

  3. #3
    Registered User
    Join Date
    Jun 2017
    Posts
    4
    Thank you, but is says: iostream: no such file or directory

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Are you trying to learn C or C++? If you are trying to learn C, then you are reading the wrong material. If you are trying to learn C++, then you are reading poorly written material and posting in the wrong place, and probably using the wrong compiler (i.e., you should use g++ instead of plain gcc, which by default does not link to C++ libraries, hence your problem).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jun 2017
    Posts
    4
    Ok I'm trying to learn C not C++, and reading tutorial in this website which should be correct I assume.

    Ok when I used g++ it all worked well, thanks

    So does that mean even if I write C code, I should always compile with g++ ?
    Last edited by Kemal; 06-14-2017 at 02:55 AM.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    There are separate C and C++ tutorials.
    C C Tutorial - Learn C - Cprogramming.com
    C++ C++ Tutorial - Learn C++ - Cprogramming.com

    It helps if you can aim a mouse I guess.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jun 2017
    Posts
    4
    Thank you Salem, regards

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need to find a header file
    By tharpa in forum C Programming
    Replies: 7
    Last Post: 10-05-2016, 11:01 AM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. Replies: 4
    Last Post: 12-14-2005, 02:21 PM
  4. Can't find Header File!
    By HowardS. in forum C++ Programming
    Replies: 5
    Last Post: 04-03-2002, 06:59 PM
  5. Where to find the code for Header File FUnctions
    By vsriharsha in forum C Programming
    Replies: 1
    Last Post: 04-02-2002, 12:37 PM

Tags for this Thread