std::skipws, std::noskipws
來自 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 的建構函式執行,它讀取並丟棄被流的當前區域設定(imbued locale)的 std::ctype facet 分類為空白字元的字元。
這是一個 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 標誌(函式) | |
消耗空白字元 (函式模板) |