std::basic_ostream<CharT,Traits>::put
提供: cppreference.com
<tbody>
</tbody>
basic_ostream& put( char_type ch ); |
||
UnformattedOutputFunction として動作します。 sentry オブジェクトの構築および確認の後、文字 ch を出力ストリームに書き込みます。
何らかの理由で出力が失敗した場合は badbit を設定します。
引数
| ch | - | 書き込む文字 |
戻り値
*this。
ノート
書式付きの operator<< と異なり、この関数は signed char または unsigned char 型に対してオーバーロードされていません。
書式付き出力関数と異なり、この関数は出力が失敗した場合に failbit をセットしません。
例
Run this code
#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
関連項目
| 文字データを挿入します (関数テンプレート) | |
| 文字のブロックを挿入します (パブリックメンバ関数) |