标准库头文件 <ostream>

来自cppreference.com
< cpp‎ | header
 
 
 

此头文件是输入/输出库的一部分。

包装给定的抽象设备(std::basic_streambuf
并提供高层输出接口
(类模板)
std::ostream basic_ostream<char>
(typedef)
std::wostream basic_ostream<wchar_t>
(typedef)

函数

插入字符数据
(函数)
操纵符
输出 '\0'
(函数模板)
冲洗输出流
(函数模板)
输出 '\n' 并冲洗输出流
(函数模板)

概要

namespace std {
    template <class charT, class traits = char_traits<charT> >
        class basic_ostream;
    typedef basic_ostream<char>    ostream;
    typedef basic_ostream<wchar_t> wostream;
 
    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, class T>
        basic_ostream<charT, traits>&
        operator<<(basic_ostream<charT, traits>&& os, const T& x);
 
    // 字符插入
    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 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*);
}


std::basic_ostream

template <class charT, class traits = char_traits<charT> >
class basic_ostream : virtual public basic_ios<charT,traits> {
public:
    // 类型(继承自 basic_ios):
    typedef charT                     char_type;
    typedef typename traits::int_type int_type;
    typedef typename traits::pos_type pos_type;
    typedef typename traits::off_type off_type;
    typedef traits                    traits_type;
 
    // 构造函数/析构函数:
    explicit basic_ostream(basic_streambuf<char_type,traits>* sb);
    virtual ~basic_ostream();
 
    // 前缀/后缀:
    class sentry;
 
    // 有格式输出:
    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<<(
        basic_streambuf<char_type,traits>* sb);
 
    // 无格式输出:
    basic_ostream<charT,traits>& put(char_type c);
    basic_ostream<charT,traits>& write(const char_type* s, streamsize n);
 
    basic_ostream<charT,traits>& flush();
 
    // 寻位:
    pos_type tellp();
    basic_ostream<charT,traits>& seekp(pos_type);
    basic_ostream<charT,traits>& seekp(off_type, ios_base::seekdir);
 
protected:
    basic_ostream(const basic_ostream& rhs) = delete;
    basic_ostream(basic_ostream&& rhs);
 
    // 赋值/交换
    basic_ostream& operator=(basic_ostream& rhs) = delete;
    basic_ostream& operator=(const basic_ostream&& rhs);
    void swap(basic_ostream& rhs);
};