C++ ios Library - Unitbuf Function



Description

It is used to sets the unitbuf "format" flag for the str stream. When the unitbuf flag is set, the associated buffer is flushed after each insertion operation.

Declaration

Following is the declaration for std::unitbuf function.

ios_base& unitbuf (ios_base& str);

Parameters

str − Stream object whose format flag is affected.

Return Value

It returns Argument str.

Exceptions

Basic guarantee − if an exception is thrown, str is in a valid state.

Data races

It modifies str. Concurrent access to the same stream object may cause data races.

Example

In below example explains about std::unitbuf function.

#include <ios>         
#include <fstream>     

int main () {
   std::ofstream outfile ("test.txt");
   outfile << std::unitbuf <<  "Test " << "file" << '\n';  
   outfile.close();
   return 0;
}
ios.htm
Advertisements