std::skipws, std::noskipws
来自 cppreference.cn
定义于头文件 <ios> |
||
std::ios_base& skipws( std::ios_base& str ); |
(1) | |
std::ios_base& noskipws( std::ios_base& str ); |
(2) | |
启用或禁用格式化输入函数跳过前导空白符(默认启用)。对输出没有影响。
空白符跳过由 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 标志(函数) | |
消耗空白符 (函数模板) |