std::resetiosflags
來自 cppreference.com
定義於標頭檔案 <iomanip> |
||
/*未指定*/ resetiosflags( std::ios_base::fmtflags mask ); |
||
當在表示式 out << resetiosflags(mask) 或 in >> resetiosflags(mask) 中使用時,根據 mask 指定清除流 out 或 in 的所有格式標誌。
目錄 |
[編輯] 引數
mask | - | 要清除的標誌的位掩碼 |
[編輯] 返回值
一個未指定型別的物件,使得
- 若 out 是型別 std::basic_ostream<CharT, Traits> 的物件,則表示式 out << resetiosflags(mask)
- 具有型別 std::basic_ostream<CharT, Traits>&
- 值為 out
- 行為如同呼叫 f(out, mask)
- 若 in 是型別 std::basic_istream<CharT, Traits> 的物件,則表示式 in >> resetiosflags(mask)
- 具有型別 std::basic_istream<CharT, Traits>&
- 值為 in
- 行為如同呼叫 f(in, mask)
其中函式 f 定義為
void f(std::ios_base& str, std::ios_base::fmtflags mask) { // reset specified flags str.setf(ios_base::fmtflags(0), mask); }
[編輯] 示例
執行此程式碼
#include <iomanip> #include <iostream> #include <sstream> int main() { std::istringstream in("10 010 10 010 10 010"); int n1, n2; in >> std::oct >> n1 >> n2; std::cout << "Parsing \"10 010\" with std::oct gives: " << n1 << ' ' << n2 << '\n'; in >> std::dec >> n1 >> n2; std::cout << "Parsing \"10 010\" with std::dec gives: " << n1 << ' ' << n2 << '\n'; in >> std::resetiosflags(std::ios_base::basefield) >> n1 >> n2; std::cout << "Parsing \"10 010\" with autodetect gives: " << n1 << ' ' << n2 << '\n'; }
輸出
Parsing "10 010" with std::oct gives: 8 8 Parsing "10 010" with std::dec gives: 10 10 Parsing "10 010" with autodetect gives: 10 8
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 183 | C++98 | resetiosflags 只能用於型別為 std::ostream 或 std::istream 的流 |
可用於任何 字元流 |
[編輯] 參閱
設定特定格式標誌 ( std::ios_base 的公共成員函式) | |
設定指定的 ios_base 標誌(函式) |