名前空間
変種
操作

std::basic_ostream<CharT,Traits>::put

From cppreference.com
< cpp‎ | io‎ | basic_ostream
 
 
 
 
basic_ostream& put( char_type ch );

UnformattedOutputFunction として動作します。sentry オブジェクトを構築してチェックした後、文字 ch を出力ストリームに書き込みます。

出力がいかなる理由で失敗した場合も、badbit を設定します。

目次

[編集] パラメータ

文字 - 書き込む文字

[編集] 戻り値

*this

[編集] 注記

この関数は、フォーマットされた operator<< とは異なり、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

[編集] 関連項目

文字データを挿入する、または右辺値ストリームに挿入する
(function template) [編集]
文字ブロックを挿入する
(public member function) [編集]
English 日本語 中文(简体) 中文(繁體)