命名空间
变体
操作

std::resetiosflags

来自 cppreference.cn
< cpp‎ | io‎ | manip
 
 
 
输入/输出 操纵符
浮点格式化
整数格式化
布尔格式化
字段宽度和填充控制
其他格式化
空白处理
输出刷新
(C++20)  

状态标志操作
resetiosflags
时间和货币 I/O
(C++11)
(C++11)
(C++11)
(C++11)
引用操纵符
(C++14)
 
定义于头文件 <iomanip>
/*unspecified*/ resetiosflags( std::ios_base::fmtflags mask );

当在表达式 out << resetiosflags(mask)in >> resetiosflags(mask) 中使用时,清除流 outin 的所有格式标志,由 mask 指定。

目录

[编辑] 参数

mask - 要清除的标志的位掩码

[编辑] 返回值

未指定类型的对象,使得

  • 如果 outstd::basic_ostream<CharT, Traits> 类型的对象,则表达式 out << resetiosflags(mask)
    • 具有类型 std::basic_ostream<CharT, Traits>&
    • 具有值 out
    • 行为如同调用了 f(out, mask)
  • 如果 instd::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++ 标准。

DR 应用于 已发布行为 正确行为
LWG 183 C++98 resetiosflags 只能用于
std::ostreamstd::istream 类型的流
可用于任何
字符流

[编辑] 参见

设置特定格式标志
(std::ios_base 的公共成员函数) [编辑]
设置指定的 ios_base 标志
(函数) [编辑]