GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::setbuf(3) C++ Standard Libary std::setbuf(3)

std::setbuf - std::setbuf


Defined in header <cstdio>
void setbuf( std::FILE* stream, char* buffer );


Sets the internal buffer to use for I/O operations performed on the C stream stream.


If buffer is not null, equivalent to std::setvbuf(stream, buffer, _IOFBF, BUFSIZ)


If buffer is null, equivalent to std::setvbuf(stream, nullptr, _IONBF, 0), which
turns off buffering.


stream - the file stream to set the buffer to.
pointer to a buffer for the stream to use. If a null pointer is supplied,
buffer - the buffering is turned off. If not null, must be able to hold at least
BUFSIZ characters


(none)


If BUFSIZ is not the appropriate buffer size, std::setvbuf can be used to change it.


std::setvbuf should also be used to detect errors, since std::setbuf does not
indicate success or failure.


This function may only be used after stream has been associated with an open file,
but before any other operation (other than a failed call to
std::setbuf/std::setvbuf).


A common error is setting the buffer of stdin or stdout to an array whose lifetime
ends before the program terminates:


int main() {
char buf[BUFSIZ];
std::setbuf(stdin, buf);
} // lifetime of buf ends, undefined behavior


std::setbuf may be used to disable buffering on streams that require immediate
output

// Run this code


#include <cstdio>
#include <thread>
#include <chrono>


int main()
{
using namespace std::chrono_literals;


std::setbuf(stdout, nullptr); // unbuffered stdout
std::putchar('a'); // appears immediately on unbuffered stream
std::this_thread::sleep_for(1s);
std::putchar('b');
}


ab


setvbuf sets the buffer and its size for a file stream
(function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.