读取输入流而不提取
Reading an input stream without extracting
我试图将输入流中的字符数计算到第一个非数字,而无需实际从流中提取字符。 输入可以包含任意数量的字符。 我需要这样做来确定在将数组中的流中的数字存储之前是否应该增长动态数组。
我仅限于以下库:iostream,cstring,cctype
我在想这样的事情:
int counter = 0;
const char * s = cin.getline();
while( s[counter] <= '0' || s[counter] >= '9' )
{
counter++;
}
但是我很难让它工作。 任何建议将不胜感激!
尝试类似操作:
std::istream::pos_type start = is.tellg();
while (std::isdigit((is >> std::ws).peek()) && is.ignore())
;
counter = in.tellg();
is.seekg(start, std::ios_base::beg);
在这种情况下,空格算作非数字字符吗?如果是这样,请从丢弃前导空格的while()
循环中删除第二行。
相关文章:
- 如何忽略输入流中的某些字符?
- 清除输入缓冲区后未提取字符串流
- C++输入流.与 cin unget() 函数有点混淆
- 从输入流中读取行,并能够跳过块
- 使用 Visual Studio 代码读取 C++ 中的输入流时出错
- 处理输入流运算符>>中的无效输入
- 树莓派上的端口音频,找不到输入流的设备
- 如何将C++输入流分隔符包含在结果令牌中
- 如果两个输入流相等,我如何构造主()到输出是
- 使用非成员函数从输入流中提取类对象
- CIN是否将输入流中的无效字符取用
- 动态内存分配和输入(流)运算符C++
- 从 std::copy 和 std::copy_n 中提取输入迭代器
- 计算输入流中值的出现次数
- (C++) 学习向量 - 编码/输入流终止/比较向量的问题
- 如何从 SYCL 内核中提取控制流?
- 为什么输入流无法识别 Ctrl D 并给出无限循环
- java 输入流,字节大,然后是 127
- 检查是否为输入流设置了Skipws/noskipws标志
- 读取输入流而不提取