Standard library header <ostream>

From cppreference.com
< cpp‎ | header
 
 
Standard Library headers
Note: a slash '/' in a revision mark means that the header was deprecated and/or removed.
Language Support
Concepts
<concepts> (C++20)
Diagnostics
<system_error> (C++11)
General utilities
<bitset>
<tuple> (C++11)
<optional> (C++17)
<any> (C++17)
<variant> (C++17)
<type_traits> (C++11)
<ratio> (C++11)
<chrono> (C++11)
Strings
<charconv> (C++17)
<format> (C++20)

<cwchar>
<cuchar> (C++11)

Localization
<codecvt> (C++11/17)

Containers
<span> (C++20)
<array> (C++11)
<vector>
Iterators
<iterator>
Ranges
<ranges> (C++20)
Algorithms
<execution> (C++17)
Numerics
<bit> (C++20)
<numbers> (C++20)
<cfenv> (C++11)
<cmath>
Input/Output
<istream>
<ostream>
<iostream>

<cstdio>
<cinttypes> (C++11)
<strstream> (C++98/)

Regular expressions
<regex> (C++11)
Filesystem support
<filesystem> (C++17)
Thread support
<thread> (C++11)
<atomic> (C++11)
<mutex> (C++11)
<shared_mutex> (C++14)
<condition_variable> (C++11)  
<future> (C++11)
<stop_token> (C++20)
<semaphore> (C++20)

<latch> (C++20)
<barrier> (C++20)

C compatibility
<cstdbool> (C++11/17/20)
<ccomplex> (C++11/17/20)
<ctgmath> (C++11/17/20)
<cstdalign> (C++11/17/20)
<ciso646> (until C++20)
<stdatomic.h>
 

This header is part of the Input/output library.

Classes

wraps a given abstract device (std::basic_streambuf)
and provides high-level output interface
(class template)
std::ostream std::basic_ostream<char>
(typedef)
std::wostream std::basic_ostream<wchar_t>
(typedef)

Functions

inserts character data or insert into rvalue stream
(function template)
Manipulators
outputs '\n' and flushes the output stream
(function template)
outputs '\0'
(function template)
flushes the output stream
(function template)
controls whether a stream's basic_syncbuf emits on flush
(function template)
flushes a stream and emits the content if it is using a basic_syncbuf
(function template)

Synopsis

namespace std {
  template<class CharT, class Traits = char_traits<CharT>>
    class basic_ostream;
 
  using ostream  = basic_ostream<char>;
  using wostream = basic_ostream<wchar_t>;
 
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>& endl(basic_ostream<CharT, Traits>& os);
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>& ends(basic_ostream<CharT, Traits>& os);
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>& flush(basic_ostream<CharT, Traits>& os);
 
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>& emit_on_flush(basic_ostream<CharT, Traits>& os);
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>& noemit_on_flush(basic_ostream<CharT, Traits>& os);
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>& flush_emit(basic_ostream<CharT, Traits>& os);
 
  template<class Ostream, class T>
    Ostream&& operator<<(Ostream&& os, const T& x);
}

Class template std::basic_ostream

namespace std {
  template<class CharT, class Traits = char_traits<CharT>>
  class basic_ostream : virtual public basic_ios<CharT, Traits> {
  public:
    // types (inherited from basic_ios)
    using char_type   = CharT;
    using int_type    = typename Traits::int_type;
    using pos_type    = typename Traits::pos_type;
    using off_type    = typename Traits::off_type;
    using traits_type = Traits;
 
    // constructor/destructor
    explicit basic_ostream(basic_streambuf<char_type, Traits>* sb);
    virtual ~basic_ostream();
 
    // prefix/suffix
    class sentry;
 
    // formatted output
    basic_ostream<CharT, Traits>&
      operator<<(basic_ostream<CharT, Traits>& (*pf)(basic_ostream<CharT, Traits>&));
    basic_ostream<CharT, Traits>&
      operator<<(basic_ios<CharT, Traits>& (*pf)(basic_ios<CharT, Traits>&));
    basic_ostream<CharT, Traits>&
      operator<<(ios_base& (*pf)(ios_base&));
 
    basic_ostream<CharT, Traits>& operator<<(bool n);
    basic_ostream<CharT, Traits>& operator<<(short n);
    basic_ostream<CharT, Traits>& operator<<(unsigned short n);
    basic_ostream<CharT, Traits>& operator<<(int n);
    basic_ostream<CharT, Traits>& operator<<(unsigned int n);
    basic_ostream<CharT, Traits>& operator<<(long n);
    basic_ostream<CharT, Traits>& operator<<(unsigned long n);
    basic_ostream<CharT, Traits>& operator<<(long long n);
    basic_ostream<CharT, Traits>& operator<<(unsigned long long n);
    basic_ostream<CharT, Traits>& operator<<(float f);
    basic_ostream<CharT, Traits>& operator<<(double f);
    basic_ostream<CharT, Traits>& operator<<(long double f);
 
    basic_ostream<CharT, Traits>& operator<<(const void* p);
    basic_ostream<CharT, Traits>& operator<<(const volatile void* val);
    basic_ostream<CharT, Traits>& operator<<(nullptr_t);
    basic_ostream<CharT, Traits>& operator<<(basic_streambuf<char_type, Traits>* sb);
 
    // unformatted output
    basic_ostream<CharT, Traits>& put(char_type c);
    basic_ostream<CharT, Traits>& write(const char_type* s, streamsize n);
 
    basic_ostream<CharT, Traits>& flush();
 
    // seeks
    pos_type tellp();
    basic_ostream<CharT, Traits>& seekp(pos_type);
    basic_ostream<CharT, Traits>& seekp(off_type, ios_base::seekdir);
 
  protected:
    // copy/move constructor
    basic_ostream(const basic_ostream&) = delete;
    basic_ostream(basic_ostream&& rhs);
 
    // assign and swap
    basic_ostream& operator=(const basic_ostream&) = delete;
    basic_ostream& operator=(basic_ostream&& rhs);
    void swap(basic_ostream& rhs);
  };
 
  // character inserters
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>& operator<<(basic_ostream<CharT, Traits>&, CharT);
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>& operator<<(basic_ostream<CharT, Traits>&, char);
  template<class Traits>
    basic_ostream<char, Traits>& operator<<(basic_ostream<char, Traits>&, char);
 
  template<class Traits>
    basic_ostream<char, Traits>& operator<<(basic_ostream<char, Traits>&, signed char);
  template<class Traits>
    basic_ostream<char, Traits>& operator<<(basic_ostream<char, Traits>&, unsigned char);
 
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, wchar_t) = delete;
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, char8_t) = delete;
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, char16_t) = delete;
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, char32_t) = delete;
  template<class Traits>
    basic_ostream<wchar_t, Traits>&
      operator<<(basic_ostream<wchar_t, Traits>&, char8_t) = delete;
  template<class Traits>
    basic_ostream<wchar_t, Traits>&
      operator<<(basic_ostream<wchar_t, Traits>&, char16_t) = delete;
  template<class Traits>
    basic_ostream<wchar_t, Traits>&
      operator<<(basic_ostream<wchar_t, Traits>&, char32_t) = delete;
 
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>&
      operator<<(basic_ostream<CharT, Traits>&, const CharT*);
  template<class CharT, class Traits>
    basic_ostream<CharT, Traits>&
      operator<<(basic_ostream<CharT, Traits>&, const char*);
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, const char*);
 
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, const signed char*);
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, const unsigned char*);
 
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, const wchar_t*) = delete;
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, const char8_t*) = delete;
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, const char16_t*) = delete;
  template<class Traits>
    basic_ostream<char, Traits>&
      operator<<(basic_ostream<char, Traits>&, const char32_t*) = delete;
  template<class Traits>
    basic_ostream<wchar_t, Traits>&
      operator<<(basic_ostream<wchar_t, Traits>&, const char8_t*) = delete;
  template<class Traits>
    basic_ostream<wchar_t, Traits>&
      operator<<(basic_ostream<wchar_t, Traits>&, const char16_t*) = delete;
  template<class Traits>
    basic_ostream<wchar_t, Traits>&
      operator<<(basic_ostream<wchar_t, Traits>&, const char32_t*) = delete;
}

Class std::basic_ostream::sentry

namespace std {
  template<class CharT, class Traits = char_traits<CharT>>
  class basic_ostream<CharT, Traits>::sentry {
    bool ok_;       // exposition only
  public:
    explicit sentry(basic_ostream<CharT, Traits>& os);
    ~sentry();
    explicit operator bool() const { return ok_; }
 
    sentry(const sentry&) = delete;
    sentry& operator=(const sentry&) = delete;
  };
}