library's source

how can I look at a library's source like iostream?
Last edited on
Why would you want to do that?
I just want to see how it works
i would not want to do that... jeez.. modifying the standard library is evil..
no I just want to see how it works :)
find where your compiler is located in your computer and there should be a folder called include, there you will find the iostream file or iostream.h
I don't want the header I want the source
i dont know, but it think that should be an assembly code.. though i'm not sure.. i think that is usually hidden to the user of the compiler..
The stream family of headers contains everything related to templates, inheritance, etc. Some classes call printf() and related functions, and those calls are in the headers. The implementation of printf() is normally in a static library that will be linked by the compiler. You may or may not be able to access this implementation, depending on the compiler. In any case, it's really nothing out of the ordinary in most cases. Just a bit of parsing for the format string. Most of the real work related to I/O is done by the OS.
thx. Are pointers used to talk to the os?
Um... Sure. Although I don't really know how knowing that helps you at all.
well that's kinda the whole thing. The reason I wanted to look at the source was because I wanted to know how the program did things like talked to the graphiccard and other components of the computer. the only way I could see it doing this was with pointers. getting and changing things in memory.
Last edited on
Well, okay, but the thing is, of course it uses pointers. There's very little you can do on a computer that doesn't involve pointers, and there's absolutely nothing that doesn't involve reading from and writing to memory.

I'll try to give you a rough idea of how writing "Hello, World!" to a console works:
1. Program sends string to printf().
2. printf() sends string to OS.
3. OS sees that the program is directing output to another process (it may also be directing it to the file system), so it pipes the string to that process.
4. Console process receives the output, modifies its own state (e.g. by writing the string to its screen buffer) and updates its drawing area.
5. Windowing system receives update signal from the console process and redraws the area by sending the updated data to the display. Exactly how this is done is heavily hardware dependent, and quite frankly I have no idea, so let's just say it calls the graphics driver and tells it to update a portion of the screen. The implementation details are left to the hardware manufacturer.
6. The picture comes out the back of the computer and finally gets to the physical screen.
He does have a point. You don't really want to modify a base library..however I have looked them over and it is VERY helpful...but to be honest if you want to look at it to learn how it works..for the purpose of trying to learn more..you might be better off looking up the API. However if you double click on the include..for example include a header into your main.cpp file and then double click on it, most of the editors will open the source for that file in another window...then if you see other source files in that header..double click on them and they will open as well. I don't recommend messing with them, but it can be great to learn from.
There is source available online for GNU glibc and libstdc++ (see my profile). Typically, you'd have to download and expand the source package(s).

I like to 'see how they did that' sometimes, myself.
Last edited on
Topic archived. No new replies allowed.