C examples for stdio.h:setvbuf
function
<cstdio> <stdio.h>
Change stream buffering by setting the mode and size of the buffer (in bytes).
int setvbuf ( FILE * stream, char * buffer, int mode, size_t size );
Parameter | Description |
---|---|
stream | FILE object. |
buffer | User allocated buffer at least size bytes long. |
mode | a mode for file buffering. |
size | Buffer size, in bytes. |
Three special macro constants:
mode | Description |
---|---|
_IOFBF | Full buffering |
_IOLBF | Line buffering |
_IONBF | No buffering. |
On success, a zero value is returned.
Otherwise, a non-zero value is returned.
A full buffer of 1024 bytes is requested for the associated stream.
This stream should only be written to the file each time the 1024-byte buffer is filled.
#include <stdio.h> int main ()// w ww . j a v a 2 s . c o m { FILE *pFile; pFile=fopen ("main.cpp","w"); setvbuf ( pFile , NULL , _IOFBF , 1024 ); // File operations here fclose (pFile); return 0; }