C++ 有办法吗?检查打开的 fstream 文件的一行是否包含多个整数?
我用以下文本打开了 myfile.in:Going
1
4 5
3
for every number while (myfile >> var) cout <<变量 << endl;
会一一输出每个整数:
1
4
5
3
有什么办法可以检查 myfile.in
的所有行并输出超过 1 个整数的行吗?对于上面的例子:
4 5
或者
4
5
I have myfile.in
opened with the following text:
1
4 5
3
Going for every number while (myfile >> var) cout << var << endl;
will output each integer one by one:
1
4
5
3
Is there any way I can check all the lines of myfile.in
and output the lines with more than 1 integer? For the example above:
4 5
or
4
5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以结合使用
std::getline
和std::istringstream
,如下所示。注释中给出了解释。演示。
You can use a combination of
std::getline
andstd::istringstream
as shown below. The explanation is given in the comments.Demo.