Location of iostream.h in GCC

I am returning to the C ++ world after almost a decade. I installed GCC and wrote a preliminary program in my Windows 7 window. I have the following question:

When I say #include <iostream.h> , I get an error when the file is not found. I have to say #include <iostream> for it to work. Also, when I go to the folder where GCC is installed, I could not find the listener file by any name. Where does iostream get out of?

+7
source share
6 answers

<iostream> is the standard C ++ header to be included. Where it depends on your platform. On mine, he is in

/usr/include/++/4.4.3/iostream

You can find out the details of g++ configuration with

g ++ --verbose

It prints, among other things,

- c-GXX-include directories = / USR / include / C ++ / 4.4

+5
source

.H headers (for example, iostream.h ) are deprecated in favor of "modern" style headers ( iostream ). This ensures that the implementation does not have to provide headers in the form of a file physically located on disk. You can choose any suitable implementation.

For example, <math.h> requires the implementation to provide a file with this name, but if you specify only <cmath> , the implementation can provide math utilities as it sees fit without a physical file.

In addition, .h headers place their declarations in the global namespace, while non-.h headers place their declarations in the std . As a result, new headers are unlikely to cause name conflicts.

Change Basile Starynkevitch in a comment, this concept is not limited to C ++, but the C standard also supports it.

+4
source

In C ++ there is no iostream.h header, it was on pre-standard days. There is no C ++ standard library header in .h .

If your installation of the compiler is reasonable, you will never have to add a directory containing standard library headers to your include directories - the compiler already knows better where to look.

+3
source

In my Windows window, iostream (now without .h ) is located in :\cygwin\lib\gcc\i686-pc-cygwin\4.5.3\include . (I searched for it due to an eclipse error and searched Google and my HD.)

+2
source

In fact, you can find it in the GCC source code:
libstdc++-v3/include/std/iostream
Without .h extension
Example for GCC-4.7

+1
source

Use the -CC option of the GCC preprocessor to display each included header.

And, as others have told you, standard C ++ headers no longer end in .h or .hh

(My suggestion is to use .hh for your own C ++ and .cc header files for your C ++ source files, I also suggest using GCC 4.7 and encode C ++ 2011 code, especially with the auto keyword to output the type of initialized local variables)

+1
source

All Articles