Re: is std::ifstream buffered or not?
kanze wrote:
[]
I understand std::cout and std::cin are buffered, and it makes
sense that they are. However, I do not see why std::ifstream
and std::ofstream would be buffered because the filesystem and
even the harddrive does some buffering. Wouldn't that be
meaningless?
No. System requests are (or were) expensive. In fact, I would
generally say that the reverse is true: cout and cin are often
connected to interactive devices, where you don't want
buffering; ifstream and ofstream rarely are.
Then again, this could depend on the implementation. I'm not
familiar enough with the C++ STL specification.
There is a function in streambuf: setbuf, which can be used to
set a user defined buffer. But an implementation is only
required to respect it if it is used to request unbuffered IO
(which means in practice a buffer size of 1).
Is it true that there is no way to make std::streambuf unbuffered? The
standard requires underflow() to either fill the pending sequence or
return EOF, which means that the pending sequence (buffer) has to be
present. IOW, std::streambuf input buffer has to be at least one
character long.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]