std::skipws, std::noskipws
来自cppreference.com
| 在标头 <ios> 定义
|
||
| |
(1) | |
| |
(2) | |
启用或禁用有格式输入函数所做的跳过前导空白符(默认启用)。在输出上无效果。
1) 如同用调用
str.setf(std::ios_base::skipws) 启用流 str 中的 skipws 标志。2) 如同用调用
str.unsetf(std::ios_base::skipws) 禁用流 str 中的 skipws 标志。空白符的跳过由 std::basic_istream::sentry 的构造函数进行,它读取并舍弃由流所浸染的本地环境的 std::ctype 刻面分类为空白符的字符。
这是一个 I/O 操纵符,可用如 out << std::noskipws 的表达式对任何 std::basic_ostream 类型的 out 或用如 in >> std::noskipws 的表达式对任何 std::basic_istream 类型的 in 调用。
参数
| 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 标志 (函数) | |
| 消耗空白符 (函数模板) |