C++ file I/O is tougher than C file I/O. So in C++, creating a new library for file I/O is useful or not? I mean <fstream> Can anyone please tell are there any benefits in C++ file I/O ?
C++ file I/O is tougher than C file I/O. So in C++, creating a
Share
Opinion
I don’t know of any real project that uses C++ streams. They are too slow and difficult to use. There are several newer libraries like FastFormat and the Boost version that claim to be better there was a piece in the last ACCU Overload magazine about them. Personally I have used the c FILE library for the last 15 years or so in C++ and I can see no reason yet to change.
Speed
Here is small test program (I knock together quickly) to show the basic speed problem:
And the results on my PC:
As we can see just this simple example is 52x slower. I hope that there are ways to make it faster!
NOTE: changing endl to ‘\n’ in my example improved C++ streams making it only 3x slower than the FILE* streams (thanks jalf) there may be ways to make it faster.
Difficulty to use
I can’t argue that printf() is not terse but it is more flexible (IMO) and simpler to understand, once you get past the initial WTF for the macro codes.
The Question
Yes, may be there is need of a better C++ library, may be FastFormat is that library, only time will tell.
dave