• Advertisement
Sign in to follow this  

file handling with c++

This topic is 4437 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

stdio or fstream i know i can handle files with both libraries but which of these two is faster and why are there two libraries that can do the same thing, i mean what is the use of it??

Share this post


Link to post
Share on other sites
Advertisement
stdio is from the C standard library, and fstream is from the C++ standard library. As you're using C++ you should prefer to use the C++ standard library so I would recomend using fstream.

Share this post


Link to post
Share on other sites
Its pure prefence, really. I prefer to use 'the C way' instead of 'the c++ way', but thats just becuase I feel that it is more readable, at least to me. Pick wichever.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by mirza101
stdio or fstream

i know i can handle files with both libraries but which of these two is faster and why are there two libraries that can do the same thing, i mean what is the use of it??



Depending on your requirements Raw File IO can be fastest (loads file/system aligned blocks -- so is good for low level stuff and bulk loading of assets etc...)

Share this post


Link to post
Share on other sites
Roughly speaking the C style I/O routines have better performance. However, that tends to be unimportant as things like file I/O tends to be bounded by the disk access. Also, it's pretty easy to create resource leaks using C style I/O with C++ classes.

On the other hand, C++ style I/O routines have better exception safety, type safety and aren't prone to many of the errors that you can get with C style I/O.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement