Why can't g++ find iostream.h?

后端 未结 3 585
醉酒成梦
醉酒成梦 2020-11-27 20:06

I\'m trying to understand how to compile C++ programs from the command line using g++ and (eventually) Clang on Ubuntu.

I found a webpage which explains MakeFiles an

相关标签:
3条回答
  • 2020-11-27 20:41

    Another related issue that wasn't mentioned here, so I will include it for anyone's future reference, is from the command line the compiler needs the environment path variable updated to find the location of the c++ header files. In windows you can just update the path environment using the 'advanced system properties' GUI and add the location of the c++ include files. This will update the PATH environment variable in Windows cmd & Cygwin automatically upon restarting the shell.

    To update your PATH from Linux or the Cygwin shell type... PATH=$PATH:/your_path_here Example:PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/c++ Also a good idea to add just the include directory as well: PATH=$PATH:/cygdrive/c/cygwin/lib/gcc/i686-pc-mingw32/4.7.3/include/ ...or check the proper directories for the location of your installation's include files, I recommend installing mingw for use with Cygwin, which is envoked with g++.

    To install additional needed packages in Cygwin re-run the Cygwin install utility & check install from Internet to add packages from web repositories and add mingw-gcc-g++ & mingw-binutils. To compile: g++ hello.cpp -o hello

    If using the gcc utility instead compile with the command: gcc hello.cpp -o hello -lstdc++ ... to get your executable.

    As long as you have either gcc or mingw installed and the path to the c++ include files is in your path environment variable, the commands will work.

    0 讨论(0)
  • 2020-11-27 20:46

    Before the C++ language was standardized by the ISO, the header file was named <iostream.h>, but when the C++98 standard was released, it was renamed to just <iostream> (without the .h). Change the code to use #include <iostream> instead and it should compile.

    You'll also need to add a using namespace std; statement to each source file (or prefix each reference to an iostream function/object with a std:: specifier), since namespaces did not exist in the pre-standardized C++. C++98 put the standard library functions and objects inside the std namespace.

    0 讨论(0)
  • 2020-11-27 20:50

    <iostream.h> has never been a standard C++ header, because it did not make it into the C++ standard.

    Instead we got <iostream>, in 1998.

    Steer well clear of teaching material using non-standard stuff such as <iostream.h> or void main.

    However, as a practical solution for your current pre-standard code, you may try to replace

    #include <iostream.h>
    

    with

    #include <iostream>
    using namespace std;
    

    It’s not guaranteed to work, but chances are that it will work.

    0 讨论(0)
提交回复
热议问题