iStream 不消耗字符
istream not consuming characters?
我有一个名为"is"的字符串流,包含字符串"101a0101"。我的代码在这里:
cout << is.str() << endl;
char bit;
while (is >> bit) {
if (bit == '0') /* do stuff */;
else if (bit == '1') /* do stuff */;
else break;
}
cout << is.str() << endl;
这是我的输出
output:
101a0101
101a0101
为什么我的 istringstream 不消耗字符?
使用 str()
访问流的内容将返回缓冲区中的整个字符序列。如果需要访问流的未读子序列,可以将substr()
与tellg()
一起使用:
std::string unread = is.str().substr(is.tellg());
std::cout << unread; // "a0101"
相关文章:
- iStream 运算符跳过空格字符
- 为什么 std::istream::gcount 返回的字符比预期的多一个字符
- 为什么std :: istream ::忽略丢弃字符
- 如何使用ISTream对象输入多个字符到对象的数组中?(and 0作为哨兵值.下面的我的代码将无效)
- iStream 不消耗字符
- 为什么 istream::operator>> 接受字符指针/数组?
- 类似于 istream::getline() 的东西,但带有替代的 delim 字符
- Istream 到字符串的转换,C++ 中的 个字符
- istream::getline()中有0个字符
- 从 istream 输入中一次读取一个字符
- istream::getline() 未获取最后一个字符
- 字符缓冲区的istream
- 为什么 istream::operator>> 没有占用字符的重载?
- istream末尾的字符问题
- 将 istream 中的字符回显到不寻常的"device"
- 由 istream 提取的字符>>双倍
- ostream << istream 并在空文件上测试 EOF,从 istream 获取字符的替代方法
- 如何将istream的指针移动n个字符
- iStream 对象不读取任何字符
- Istream最多使用N个空白字符