std::skipws, std::noskipws
From cppreference.com
| ヘッダ <ios>で定義 |
||
| std::ios_base& skipws( std::ios_base& str ); |
(1) | |
| std::ios_base& noskipws( std::ios_base& str ); |
(2) | |
フォーマットされた入力関数による先行空白文字のスキップを有効または無効にします(デフォルトで有効)。出力には影響しません。
空白文字のスキップは、std::basic_istream::sentry のコンストラクタによって実行されます。これは、ストリームに埋め込まれたロケールの std::ctype ファセットによって空白文字として分類される文字を読み取って破棄します。
これは I/O マニピュレータであり、std::basic_ostream 型の任意の out に対して out << std::noskipws のような式、または std::basic_istream 型の任意の in に対して in >> std::noskipws のような式で呼び出すことができます。
目次 |
[編集] パラメータ
| str | - | I/Oストリームへの参照 |
[編集] 戻り値
str (操作後のストリームへの参照)。
[編集] 例
このコードを実行
#include <iostream> #include <sstream> int main() { char c1, c2, c3; std::istringstream("a b c") >> c1 >> c2 >> c3; std::cout << "Default behavior:" " c1 = " << c1 << " c2 = " << c2 << " c3 = " << c3 << '\n'; std::istringstream("a b c") >> std::noskipws >> c1 >> c2 >> c3; std::cout << "noskipws behavior:" " c1 = " << c1 << " c2 = " << c2 << " c3 = " << c3 << '\n'; }
出力
Default behavior: c1 = a c2 = b c3 = c noskipws behavior: c1 = a c2 = c3 = b
[編集] 関連項目
| 指定されたios_baseフラグをクリアする (関数) | |
指定されたios_baseフラグを設定する(関数) | |
| 空白文字を消費する (関数テンプレート) |