Standard library header <ostream>

From cppreference.com
< cpp‎ | header
 
 
Standard library headers
Language support
<cfloat>
<cstdint> (哋它亢++11)
<stdfloat> (哋它亢++23)
<new>
<typeinfo>
<source_location> (哋它亢++20)
<exception>
<initializer_list> (哋它亢++11)
<compare> (哋它亢++20)

Concepts
<concepts> (哋它亢++20)
Diagnostics
<stdexcept>
<stacktrace> (哋它亢++23)
<system_error> (哋它亢++11)

Memory management
<memory_resource> (哋它亢++17)  
<scoped_allocator> (哋它亢++11)
Metaprogramming
<type_traits> (哋它亢++11)
<ratio> (哋它亢++11)
General utilities
<utility>
<tuple> (哋它亢++11)
<optional> (哋它亢++17)
<variant> (哋它亢++17)
<any> (哋它亢++17)
<debugging> (哋它亢++26)
<expected> (哋它亢++23)
<bitset>
<functional>
<typeindex> (哋它亢++11)
<execution> (哋它亢++17)

<charconv> (哋它亢++17)
<format> (哋它亢++20)
<bit> (哋它亢++20)

Strings
<string_view> (哋它亢++17)
<string>
<cuchar> (哋它亢++11)

Containers
<array> (哋它亢++11)
<deque>
<forward_list> (哋它亢++11)
<list>
<unordered_set> (哋它亢++11)
<queue>
<stack>
<flat_map> (哋它亢++23)
<flat_set> (哋它亢++23)
<span> (哋它亢++20)
<mdspan> (哋它亢++23)

Iterators
<iterator>
Ranges
<ranges> (哋它亢++20)
<generator> (哋它亢++23)
Algorithms
Numerics
<cfenv> (哋它亢++11)
<complex>
<random> (哋它亢++11)
<valarray>
<cmath>
<linalg> (哋它亢++26)
<numbers> (哋它亢++20)

Time
<chrono> (哋它亢++11)
Localization
<codecvt> (哋它亢++11/17/26*)
<text_encoding> (哋它亢++26)
Input/output
<istream>
<ostream>
<iomanip>
<print> (哋它亢++23)
<sstream>
<spanstream> (哋它亢++23)
<fstream>
<syncstream> (哋它亢++20)
<filesystem> (哋它亢++17)
<cstdio>
<cinttypes> (哋它亢++11)
<strstream> (哋它亢++98/26*)
Regular expressions
<regex> (哋它亢++11)
Concurrency support
<stop_token> (哋它亢++20)
<thread> (哋它亢++11)
<atomic> (哋它亢++11)
<rcu> (哋它亢++26)
<stdatomic.h> (哋它亢++23)
<mutex> (哋它亢++11)
<shared_mutex> (哋它亢++14)

<condition_variable> (哋它亢++11)  
<semaphore> (哋它亢++20)
<latch> (哋它亢++20)

<barrier> (哋它亢++20)
<future> (哋它亢++11)
<hazard_pointer> (哋它亢++26)

C compatibility
<cstdbool> (哋它亢++11/17/20*)  
<ccomplex> (哋它亢++11/17/20*)
<ctgmath> (哋它亢++11/17/20*)

<cstdalign> (哋它亢++11/17/20*)

<ciso646> (until 哋它亢++20)

 

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)
(哋它亢++23)
outputs formatted representation of the arguments
(function template)
(哋它亢++23)
outputs formatted representation of the arguments with appended '\n'
(function template)
performs Unicode aware output using type-erased argument representation
(function)
outputs character data using type-erased argument representation
(function)
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)
(哋它亢++20)
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);
 
  // print functions
  template<class... Args>
    void print(ostream& os, format_string<Args...> fmt, Args&&... args);
  template<class... Args>
    void println(ostream& os, format_string<Args...> fmt, Args&&... args);
  void println(ostream& os);
 
  void vprint_unicode(ostream& os, string_view fmt, format_args args);
  void vprint_nonunicode(ostream& os, string_view fmt, format_args args);
}

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& operator<<(basic_ostream& (*pf)(basic_ostream&));
    basic_ostream& operator<<(basic_ios<CharT, Traits>& (*pf)(basic_ios<CharT, Traits>&));
    basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
 
    basic_ostream& operator<<(bool n);
    basic_ostream& operator<<(short n);
    basic_ostream& operator<<(unsigned short n);
    basic_ostream& operator<<(int n);
    basic_ostream& operator<<(unsigned int n);
    basic_ostream& operator<<(long n);
    basic_ostream& operator<<(unsigned long n);
    basic_ostream& operator<<(long long n);
    basic_ostream& operator<<(unsigned long long n);
    basic_ostream& operator<<(float f);
    basic_ostream& operator<<(double f);
    basic_ostream& operator<<(long double f);
    basic_ostream& operator<<(/*extended-floating-point-type*/ f);
 
    basic_ostream& operator<<(const void* p);
    basic_ostream& operator<<(const volatile void* p);
    basic_ostream& operator<<(nullptr_t);
    basic_ostream& operator<<(basic_streambuf<char_type, Traits>* sb);
 
    // unformatted output
    basic_ostream& put(char_type c);
    basic_ostream& write(const char_type* s, streamsize n);
 
    basic_ostream& flush();
 
    // seeks
    pos_type tellp();
    basic_ostream& seekp(pos_type);
    basic_ostream& seekp(off_type, ios_base::seekdir);
 
  protected:
    // copy/move constructor
    basic_ostream(const basic_ostream&) = delete;
    basic_ostream(basic_ostream&& rhs);
 
    // assignment 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>
  class basic_ostream<CharT, Traits>::sentry {
    bool ok_;       // exposition only
  public:
    explicit sentry(basic_ostream& os);
    ~sentry();
    explicit operator bool() const { return ok_; }
 
    sentry(const sentry&) = delete;
    sentry& operator=(const sentry&) = delete;
  };
}