#include <iostream>
#include <sstream>
int main()
{
char a, b, c;
std::istringstream iss(" 123");
iss >> std::skipws >> a >> b >> c; // 忽略掉前面的空白字符,PS: 默认std::skipws是置位的
std::cout << a << b << c << std::endl; // 123
iss.seekg(0);
iss >> std::noskipws >> a >> b >> c; // 不忽略空白字符,将其读取
std::cout << a << b << c << std::endl; // ..1
return 0;
}
C++学习(四八零)noskipws skipws
最新推荐文章于 2025-07-13 10:11:47 发布
本文介绍了一个C++程序示例,演示了如何使用std::istringstream进行字符读取,并展示了skipws与noskipws标志的作用。通过该示例,读者可以了解如何控制输入流中空白字符的处理方式。
1万+

被折叠的 条评论
为什么被折叠?



