Share via


<ostream> 运算符

operator<<

operator<<

将各种类型写入流。

template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>& _Ostr,
    const Elem* str);

template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>& _Ostr,
    Elem _Ch);

template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>& _Ostr,
    const char* str);

template <class _Elem, class _Tr>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>& _Ostr,
    char _Ch);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const char* str);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _ostr,
    char _Ch);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const signed char* str);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    signed char _Ch);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const unsigned char* str);

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    unsigned char _Ch);

template <class _Elem, class _Tr, class T>
basic_ostream <_Elem, _Tr>& operator<<(
    basic_ostream<_Elem, _Tr>&& _Ostr,
    Ty val);

参数

_Ch
一个字符。

_Elem
元素类型。

_Ostr
basic_ostream 对象。

str
字符串。

_Tr
字符特征。

val
类型

返回值

流。

备注

basic_ostream 类还定义了多个插入运算符。 有关详细信息,请参阅 basic_ostream::operator<<

模板函数

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _ostr,
    const Elem *str);

确定以 str 开始的序列的长度 N = traits_type::length(str),并插入序列。 如果 N <_Ostr.width,则该函数还将插入 _Ostr.width 的重复项 - N 个填充字符。 重复项在序列前,前提是 (_Ostr. flags & adjustfield != left。 否则,重复项在该序列后。 该函数返回 _Ostr

模板函数

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    Elem _Ch);

插入元素 _Ch。 如果 1 <_Ostr.width,则该函数还将插入 _Ostr.width 的重复项 - 1 个填充字符。 如果 _Ostr.flags & adjustfield != left,则该重复项在序列前。 否则,重复项在该序列后。 它返回 _Ostr

模板函数

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    const char *str);

行为等同于

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    const Elem *str);

通过调用 _Ostr.put(_Ostr.widen(_Ch)) 将以 str 开头的序列的每个元素 _Ch 转换为 Elem 类型的对象除外

模板函数

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    char _Ch);

行为等同于

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    Elem _Ch);

通过调用 _Ostr.put( _Ostr.widen( _Ch )) 将 _Ch 转换为 Elem 类型的对象除外

模板函数

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const char *str);

行为等同于

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    const Elem *str);

(在插入元素之前,无需将其加宽。)

模板函数

template <class _Tr>
basic_ostream<char, Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    char _Ch);

行为等同于

template <class _Elem, class _Tr>
basic_ostream<Elem, _Tr>& operator<<(
    basic_ostream<Elem, _Tr>& _Ostr,
    Elem _Ch);

(在插入 _Ch 之前,无需将其加宽。)

模板函数

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const signed char *str);

返回 _Ostr << (const char *)str

模板函数

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    signed char _Ch);

返回 _Ostr << (char)_Ch

模板函数:

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    const unsigned char *str);

返回 _Ostr << (const char *)str

模板函数:

template <class _Tr>
basic_ostream<char, _Tr>& operator<<(
    basic_ostream<char, _Tr>& _Ostr,
    unsigned char _Ch);

返回 _Ostr << (char)_Ch

模板函数:

template <class _Elem, class _Tr, class T>
basic_ostream<_Elem, _Tr>& operator<<(
    basic_ostream<char, _Tr>&& _Ostr,
    T val);

返回 _Ostr << val(并将右值引用转换为进程中左值的 _Ostr)。

示例

有关使用 operator<< 的示例,请参阅 flush

另请参阅

<ostream>