命名空间
变体
操作

std::skipws, std::noskipws

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

状态标志操作
时间和货币 I/O
(C++11)
(C++11)
(C++11)
(C++11)
引用操纵符
(C++14)
 
定义于头文件 <ios>
std::ios_base& skipws( std::ios_base& str );
(1)
std::ios_base& noskipws( std::ios_base& str );
(2)

启用或禁用格式化输入函数跳过前导空白符(默认启用)。对输出没有影响。

1) 在流 str 中启用 skipws 标志,如同调用 str.setf(std::ios_base::skipws) 一样。
2) 在流 str 中禁用 skipws 标志,如同调用 str.unsetf(std::ios_base::skipws) 一样。

空白符跳过由 std::basic_istream::sentry 的构造函数执行,它读取并丢弃流的 imbuded locale 的 std::ctype facet 分类为空白符的字符。

这是一个 I/O 操纵符,可以对任何 std::basic_ostream 类型的 out 使用诸如 out << std::noskipws 的表达式调用,或者对任何 std::basic_istream 类型的 in 使用诸如 in >> std::noskipws 的表达式调用。

目录

[edit] 参数

str - I/O 流的引用

[edit] 返回值

str (操作后的流的引用)。

[edit] 示例

#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

[edit] 参见

清除指定的 ios_base 标志
(函数) [编辑]
设置指定的 ios_base 标志
(函数) [编辑]
消耗空白符
(函数模板) [编辑]