Reputation: 415
When I compile a program with #include
where can I see the contents of that file, and also since that file contains declarations, where can I see the actual code used in those functions?
Is it open to everyone or is it not available to the public?
Upvotes: 6
Views: 9172
Reputation: 37938
Run this command from your command line:
find /usr -name iostream
That will tell you the directory you want.
Upvotes: 2
Reputation: 12817
Generally the #included file is readable, but the library it implements is generally not readable. The include files on a mac are in /usr/include/c++.
The library code depends on the compiler. For Gnu C++ used in linux and Mac you can definitely see the code. You might have to download it. It is available at http://gcc.gnu.org/libstdc++/
I don't think Windows C++ library code is available.
Upvotes: 4
Reputation: 6008
The C++ standard itself is just this: a standard. The implementation of which is done by many vendors. STLport and GNU libstdc++ are both open source and can be looked at as a whole. Visual Studio ships with Dinkumware C++ standard library. It is closed source.
Nevertheless, you can always see the source of the headers by opening the include directory of your C++ standard lib. The files are named just like you include them. Much of it is implemented in headers anyway. But are pretty much unreadable to the untrained eye.
But when it comes to using the C++ library don't depend on the exact source code of it, but rather on what the C++ standard says. Don't program to an implementation, but rather to the standard.
Upvotes: 2
Reputation: 33406
The actual code is in the platform-specific standard libraries that come with your compiler, you can see it by looking at the standard library implementation source.
Here's the documentation (and source) for libstdc++
by GNU (it comes with gcc
): http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/index.html.
Download the source from one of these mirrors: http://gcc.gnu.org/mirrors.html
Upvotes: 5
Reputation: 32969
It depends on what toolchain you are using, not every vendor is making his implementation public. You can have a look at the GNU C library for starters: http://www.gnu.org/software/libc/
Dinkumware, the company behind the C++ standard template library that is used in Visual Studio for example, is offering a commercial product, thus the code is not available to everyone - it really depends on your license. Some versions of Visual Studio indeed ship with the source code of the runtime included.
As for the STL, there is also STLport, an open source STL implementation.
Your best bet will indeed be the projects that gcc/g++ depend on.
Upvotes: 2
Reputation: 28932
All system headers ship with your compiler. On Linux systems, these can normally be found under /usr/include
. On other platforms, the will normally live where you installed the compiler.
Commercial libraries do not normally ship source code. On linux, these can normally be found in the source pacakges.
Upvotes: 1
Reputation: 12799
If you use something like Visual Studio, you can put a break point and then start line-by-line stepping through your code and it will open the included files as you go along. Quickest way into a file in my opinion. Otherwise you can find the code somewhere on your PC ... on mine its in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\ostream
for example, replacing ostream with iostream, sstream, etc (note that those are file names without extensions) but also if you look at the directory you'll see a lot of .h and .c files
Upvotes: 1