public member function

std::streambuf::pubsync

<streambuf>
int pubsync ( );
Synchronize stream buffer
Calls the protected virtual member sync, which synchronizes the contents in the buffer with those of the associated character sequence, effectively writing any unwritten character in the output buffer to the physical device.

Parameters

none

Return Value

If the function is successful, the function returns zero. If it fails, it returns a value of -1.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// pubsync member
#include <iostream>
#include <fstream>
using namespace std;

int main () {

  streambuf * pbuf;
  ofstream ostr ("test.txt");  

  pbuf = ostr.rdbuf();

  pbuf->sputn ("First sentence\n",15);
  pbuf->pubsync();
  pbuf->sputn ("Second sentence\n",16);

  ostr.close();

  return 0;
}


In this example, the buffer is synchronized with the content of the file after the first sentence.

Basic template member declaration

( basic_streambuf<charT,traits> )
 
int pubsync ( );


See also