operator<<<div class="t-tr-text">(性病:: basic_ostream)<div class="t-tr-dropdown"><div><div><div class="t-tr-dropdown-arrow-border"></div><div class="t-tr-dropdown-arrow"></div><div class="t-tr-dropdown-h">原文:</div><div class="t-tr-dropdown-orig">(std::basic_ostream)</div><div class="t-tr-dropdown-notes">这段文字是通过 [http://translate.google.com Google Translate] 自动翻译生成的。<br/>您可以帮助我们检查、纠正翻译中的错误。详情请点击[http://en.cppreference.com/w/Cppreference:MachineTranslations 这里]。</div></div></div></div></div>
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
template< class CharT, class Traits> basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, |
(1) | |
template< class CharT, class Traits > basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os, |
(2) | |
template< class CharT, class Traits, class T > basic_ostream< charT, traits >& operator<<( basic_ostream<CharT,Traits>&& os, |
(3) | (C++11 起) |
sentry
,刷新tie()'d的输出缓冲区,如果必要的检查流错误。项目建成后,如果哨兵对象返回false,这些函数返回没有尝试任何输出。如果发生错误,在输出过程中,这些函数调用setstate(ios_base::failbit)。如果抛出一个异常,然后在输出的ios :: badbit(exceptions()&badbit) != 0被抑制,除非,在这种情况下,它被重新抛出异常)sentry
, which flushes the tie()'d output buffers if necessary and checks the stream errors. After construction, if the sentry object returns false, these functions return without attempting any output. If an error occurs during output, these functions call setstate(ios_base::failbit). If an exception is thrown during output, then ios::badbit is set (the exception is suppressed unless exceptions()&badbit) != 0, in which case it is rethrown)ch
。如果字符的类型是不CharT
,它首先被转化os.widen(ch)。如果第3阶段num_put::put()填充确定。在插入之后,被称为width(0).ch
. If the type of the character is not CharT
, it is first converted with os.widen(ch). Padding is determined as if by Stage 3 of num_put::put(). After insertion, width(0) is called.s
.s
.- 为第一和第三的重载(
CharT
相匹配的类型的ch
),完全相同traits::length(s)
字符被插入.原文:for the first and third overloads (whereCharT
matches the type ofch
), exactlytraits::length(s)
characters are inserted. - 第二个重载,完全std::char_traits<char>::length(s)字符插入.原文:for the second overload, exactly std::char_traits<char>::length(s) characters are inserted.
- 在过去的两个多载,正是traits::length(reinterpret_cast<const char*>(s))插入.原文:for the last two overloads, exactly traits::length(reinterpret_cast<const char*>(s)) are inserted.
目录 |
[编辑] 参数
os | - | 输出流中插入数据
|
ch | - | 参考字符插入
|
s | - | 插入一个字符串的指针
原文: pointer to a character string to insert |
[编辑] 返回值
st
[编辑] 示例
#include <iostream> #include <sstream> int main() { std::cout << "Hello, world" // the const char* overlaod << '\n'; // the char overload std::string s = (std::ostringstream() << 1.2).str(); // rvalue overload std::cout << s << '\n'; }
输出:
Hello, world 1.2
[编辑] 另请参阅
插入格式化的数据 (公共成员函数) |