I Always Wondered How... [i/o]

Started by
4 comments, last by Doc 19 years, 7 months ago
Ever since I found out about ofstream and ifstream, I've adored using them. The power of file i/o overwhelmed me. Well, now, on a different topic, I just ordered a video card to power a second monitor, and used FedEx's super saver shipping (i.e. my package won't arrive for bloody ages). I'm not really doing anything for now except waiting. So I got bored, and looked inside some header files (under the include folder of the compiler). Stumbled across "fstream.h". I opened it, but the file seemed too short to be anything useful. Is the Power of I/O really contained in that wimpy little 5KB file? And I always wondered how the actual writing/reading code would look at its lowest level. The ifstream/ofstream is really just an interface with lower level code, right? Out of curiosity and boredom, I'd really like to see the code that actually does the trick. Nothing under fstream.h looks like anything of the sort. So where is it?
.:<<-v0d[KA]->>:.
Advertisement
header file only contains the declaration as for the implementation it's in the C runtime (so in a dll) & don't quote me on that but i don't think it's an interface to low level code it actually just call OS dependant file functions (not sure if it calls winapi functions or lowers ones that get called by winapi) but either way i don't think it use anything else then winapi or the functions called by it (so nothing directly low level to see in that lib)

of course i could be totally wrong so i suggest u wait till someone with a clue answers><
Quote:Original post by ranakor
header file only contains the declaration as for the implementation it's in the C runtime (so in a dll) & don't quote me on that but i don't think it's an interface to low level code it actually just call OS dependant file functions (not sure if it calls winapi functions or lowers ones that get called by winapi) but either way i don't think it use anything else then winapi or the functions called by it (so nothing directly low level to see in that lib)

of course i could be totally wrong so i suggest u wait till someone with a clue answers><


In a... dll?... which means..... encrypted and unreadable?..... *sobs*
.:<<-v0d[KA]->>:.
Er. The fstream interfaces are part of the STL (Standard Template Library). Being templates, their implementations cannot really be stuffed into a DLL. The code is somewhere in your compiler include directory.

Also, fstream.h is nonstandard. Look in fstream.
The classes that do the actual work are the stream buffer classes, like basic_filebuf. And the actual formatting is delegated to locale facets (in <locale>) - iostreams rely on much more than a single header.

And yes, the full source code is available in the header files - just start with one of them (like <fstream> -- not <fstream.h>) and walk down the #include dependences
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Even if the actual working code is hidden away in DLLs (which is likely since fstream code must down the line make use of C code and/or OS specific code for the low level stuff anyway) you could always have a look at GNU sources to get an idea how it works. Most likely, though, you can find the important stuff in the right header files, anyway, considering they are templates.
My stuff.Shameless promotion: FreePop: The GPL god-sim.

This topic is closed to new replies.

Advertisement