operator<<(std::basic_ostream)
  | (1)  |   | 
|---|---|---|
template< class CharT, class Traits> basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, CharT ch );  |   | |
template< class CharT, class Traits> basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, char ch );  |   | |
template< class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, char ch );  |   | |
template< class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, signed char ch );  |   | |
template< class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, unsigned char ch );  |   | |
  | (2)  |   | 
template< class CharT, class Traits > basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, const CharT* s );  |   | |
template< class CharT, class Traits > basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, const char* s );  |   | |
template< class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, const char* s );  |   | |
template< class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, const signed char* s );  |   | |
template< class Traits > basic_ostream<char,Traits>& operator<<( basic_ostream<char,Traits>& os, const unsigned char* s );  |   | |
template< class CharT, class Traits, class T > basic_ostream< CharT, Traits >& operator<<( basic_ostream<CharT,Traits>&& os, const T& value );  | (3)  | (since C++11)  | 
插入字符或字符串。
1%29表现为FormattedOutputFunction在构造和检查哨兵对象之后,插入字符。ch如果字符的类型不是CharT,它首先被转换为os.widen(ch).填充物确定如下:os.width()>1,然后os.width()-1副本os.fill()添加到输出字符中,以形成输出字符序列。如果(out.flags()&std::ios_base::adjustfield)==std::ios_base::left,填充字符放在输出字符之后,否则放在前面。插入后,os.width(0)的效果。std::setw如果有的话。
2%29表现为FormattedOutputFunction.在构造和检查哨兵对象之后,从字符数组中插入连续字符,该字符数组的第一个元素由s...
- 对于四重载%28
CharT匹配类型ch%29,完全正确traits::length(s)插入字符。 
- 对于第二次超载,准确地说
std::char_traits<char>::length(s)插入字符。 
- 对于最后两个过载
traits::length(reinterpret_cast<const char*>(s))插入。 
插入前,首先,所有字符都将使用os.widen(),则按以下方式确定填充:如果要插入的字符数小于os.width(),那么足够的副本os.fill()添加到字符序列中,以使其长度相等。os.width().如果(out.flags()&std::ios_base::adjustfield)==std::ios_base::left,则在输出序列的末尾添加填充字符,否则将在输出序列之前添加填充字符。插入后,width(0)的效果。std::setw如果有的话。如果s为空指针。
3%29调用适当的插入运算符,给出对输出流对象%28的rvalue引用,该引用等价于os << value29%。此函数模板不参与重载解析,除非表达式os << value是很有条理的。%28自C++17%29
参数
os  | -  | output stream to insert data to  | 
|---|---|---|
ch  | -  | reference to a character to insert  | 
s  | -  | pointer to a character string to insert  | 
返回值
os...
注记
LLVMlibc++中重载%283%29的实现lwg#1203并返回与参数类型相同的流,以便代码(如(std::ostringstream()<<1.2).str()编译。
例
二次
#include <iostream>
#include <fstream>
 
int main()
{
    std::cout << "Hello, world" // the const char* overload
              << '\n';          // the char overload
    std::ofstream("test.txt") << 1.2; // rvalue overload
}二次
产出:
二次
Hello, world二次
另见
operator<<  | inserts formatted data (public member function)  | 
|---|---|
widen  | widens characters (public member function of std::basic_ios)  | 
 © cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

