Sign in to follow this  

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

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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><

Share this post


Link to post
Share on other sites
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*

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this