Namespaces
Variants

std:: setiosflags

From cppreference.net
< cpp ‎ | io ‎ | manip
Input/output manipulators
Floating-point formatting
Integer formatting
Boolean formatting
Field width and fill control
Other formatting
Whitespace processing
Output flushing
Status flags manipulation
setiosflags
Time and money I/O
(C++11)
(C++11)
(C++11)
(C++11)
Quoted manipulator
(C++14)
定义于头文件 <iomanip>
/*unspecified*/ setiosflags ( std:: ios_base :: fmtflags mask ) ;

当在表达式 out << setiosflags ( mask ) in >> setiosflags ( mask ) 中使用时,按照 mask 的指定设置流 out in 的所有格式标志。

目录

参数

mask - 要设置的标志位掩码

返回值

一个未指定类型的对象,使得

  • 如果 out 是类型为 std:: basic_ostream < CharT, Traits > 的对象,则表达式 out << setiosflags ( mask )
    • 具有类型 std:: basic_ostream < CharT, Traits > &
    • 具有值 out
    • 行为如同调用了 f ( out, mask )
  • 如果 in 是类型为 std:: basic_istream < CharT, Traits > 的对象,则表达式 in >> setiosflags ( mask )

其中函数 f 定义为:

void f(std::ios_base& str, std::ios_base::fmtflags mask)
{
    // 设置指定标志位
    str.setf(mask);
}

示例

#include <iomanip>
#include <iostream>
int main()
{
    std::cout << std::resetiosflags(std::ios_base::dec) 
              << std::setiosflags(  std::ios_base::hex
                                  | std::ios_base::uppercase
                                  | std::ios_base::showbase) << 42 << '\n';
}

输出:

0X2A

缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的C++标准。

缺陷报告 应用于 发布时行为 正确行为
LWG 183 C++98 setiosflags 仅能用于 std::ostream std::istream
类型的流
可用于任意
字符流

参见

设置特定格式标志
( std::ios_base 的公开成员函数)
清除指定的 ios_base 标志
(函数)