Quantcast
Channel: ntcoder » stl
Viewing all articles
Browse latest Browse all 10

Turn on/off buffering for streams in c++

$
0
0

Use io manipulator ‘unitbuf’ to turn off stream buffering and ‘nounitbuf’ to turn on stream buffering. If ‘unitbuf’ is on the stream object is flushed after every insertion else the stream is not force flushed. For e.g. endl triggers a flush in cases of ‘nounitbuf’.

Sample code:

fstream fstr( “c://Hello.txt” );

[sourcecode language=”cpp”]cout << unitbuf << "Buffering turned off";
cout << nounitbuf << "Buffering turned on";[/sourcecode]

Also note that ‘endl’ flushes stream buffer along with inserting a new line character.

The post Turn on/off buffering for streams in c++ appeared first on ntcoder.


Viewing all articles
Browse latest Browse all 10

Latest Images





Latest Images