std::basic_ostream::put
性病:基本[医]Ostream::PUT
basic_ostream& put( char_type ch | | |
---|
表现为UnformattedOutputFunction
.在构造和检查哨兵对象之后,编写字符ch
到输出流。
如果输出因任何原因失败,则设置badbit
...
参数
ch | - | character to write |
---|
返回值
*this
...
注记
此函数不会对类型重载。signed char或unsigned char,与格式化的运算符<<
与格式化输出函数不同,此函数不设置failbit
如果输出失败。
例
二次
#include <fstream>
#include <iostream>
int main()
{
std::cout.put('a' // normal usage
std::cout.put('\n'
std::ofstream s("/does/not/exist/"
s.clear( // pretend the stream is good
std::cout << "Unformatted output: ";
s.put('c' // this will set badbit, but not failbit
std::cout << " fail=" << bool(s.rdstate() & s.failbit
std::cout << " bad=" << s.bad() << '\n';
s.clear(
std::cout << "Formatted output: ";
s << 'c'; // this will set badbit and failbit
std::cout << " fail=" << bool(s.rdstate() & s.failbit
std::cout << " bad=" << s.bad() << '\n';
}
二次
产出:
二次
a
Unformatted output: fail=0 bad=1
Formatted output: fail=1 bad=1
二次
另见
operator<<(std::basic_ostream) | inserts character data (function template) |
---|---|
write | inserts blocks of characters (public member function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。