Table of Contents

<ostream>

<ostream> defines std::basic_ostream and std::ostream, the base classes for output streams. It provides operator<< for formatted output, put(), write(), and flush().

Most code uses std::cout or file output streams that inherit from this class.

Example

This example writes formatted output to a generic ostream reference and explicitly flushes the stream.

// compile: g++ -std=c++11 -o ostreamexample ostreamexample.cpp
// run: ./ostreamexample
// description: write to output stream
 
#include <ostream>
#include <iostream>
 
int main() {
    std::ostream& out = std::cout;
 
    out << "hello " << 42 << " " << 3.14 << "\n";
    out.flush();
 
    return 0;
}