通过std :: ifstream从字符串中获取每个值 [英] Get each value from a string via std::ifstream

查看:191
本文介绍了通过std :: ifstream从字符串中获取每个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在while循环中使用 ifstream 来获取每个值。但是,当我尝试它时,没有任何反应。为什么?

I am try to use an ifstream with the while loop to get each value. However, when I try it, nothing happens. Why?

std::string line;
std::getline(cin, line);
std::ifstream stream(line);
while(stream){
    std::cout << stream.get();
}


推荐答案

您必须使用 istringstream ,而不是 ifstream

这篇关于通过std :: ifstream从字符串中获取每个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆