我可以做一个循环,直到“std::cin”在输入缓冲区中看到“”字符
Can I make a loop until `std::cin` see the ` ` character in the input buffer?
像这样。
do{
int x{};
std::cin >> x;
}while(/*i want the condition mentioned here*/);
我的意思是,如果用户输入x
并按 Enter 键,我希望循环结束。我能做到吗?
最常见的方法是读取整行,然后从该行中提取数据。
也就是说,视角从"阅读事物直到遇到换行符"转变为稍微高一点的"阅读行上的所有内容"。
std::string line;
if (std::getline(std::cin, line))
{
std::stringstream ls(line);
int x = 0;
while (ls >> x)
{
// Process x
}
}
相关文章:
- 清除输入缓冲区后未提取字符串流
- 快速读取标准输入缓冲区,无需检查
- C++ 为什么还剩下输入缓冲区?
- 如果输入缓冲区不为空,请使用getchar.()检测Ctrl+d
- 如果我在 C++ 中为 int 提供双精度,输入缓冲区中存储了什么?
- 如何重复使用原始输入缓冲区内存?
- 从输入缓冲区读取
- 安全操作以清除C++中的空输入缓冲区
- 如何检查输入缓冲区是否为空
- 我可以做一个循环,直到“std::cin”在输入缓冲区中看到“”字符
- 是否可以在键盘输入缓冲区中向前看并在MFC/Win32中检测条形码条目
- fftwf_execute_dft_c2r写入输入缓冲区
- 如何在C 中清除输入缓冲区
- cin.clear() 如何清除输入缓冲区
- C++清除输入缓冲区(最后没有换行符)
- 输入缓冲区错误或其他原因
- Linux 串行端口读取 - 我可以更改输入缓冲区的大小吗?
- 清除输入缓冲区中的所有其他字符
- 如何在获得下一个字符后正确刷新输入缓冲区,而无需按两次回车键!C++
- 清除包括换行符在内的输入缓冲区