Previous fileTop of DocumentContentsIndex pageNext file
Apache C++ Standard Library User's Guide

35.6 Synchronization with the C Standard I/O

The predefined Standard Iostream objects std::cin, std::cout, std::cerr, and std::clog, and their wide character counterparts std::wcin, std::wcout, std::wcerr, and std::wclog are by default synchronized with the standard C files std::stdin, std::stdout, and std::stderr, declared in the header <cstdio>, as we saw in Section 28.1. This means that objects inserted into cout, for instance, go to the same file as output to stdout, and appear in the same order as the calls to the output functions. By default, input and output to the predefined streams are synchronized with read or write operations on the standard C files. The effect is that input and output operations are executed in the order of invocation, independently of whether the operations used the Standard Iostream objects or the standard C files.

This synchronization is time-consuming and thus might not be desirable in all situations. You can switch it off by calling the static member function:

After such a call, the predefined streams operate independently of the C standard files, with possible performance improvements in your C++ stream operations. However, for portability, you should call sync_with_stdio() prior to any input or output operation on the predefined Standard Iostream objects, because otherwise the effect of calling sync_with_stdio() is implementation-defined.



Previous fileTop of DocumentContentsIndex pageNext file