Namespaces
Variants

std:: skipws, std:: noskipws

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
skipws noskipws
Output flushing
Status flags manipulation
Time and money I/O
(C++11)
(C++11)
(C++11)
(C++11)
Quoted manipulator
(C++14)
定义于头文件 <ios>
(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 的构造函数执行,该函数会读取并丢弃被流所植入区域设置的 std::ctype 平面分类为空白符的字符。

这是一个I/O操纵器,可以通过形如 out << std :: noskipws 的表达式调用(适用于任何 out 类型的 std::basic_ostream ),或通过形如 in >> std :: noskipws 的表达式调用(适用于任何 in 类型的 std::basic_istream )。

目录

参数

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 标志
(函数)
消耗空白字符
(函数模板)