Get each value from a string via std::ifstream

假如想象 提交于 2019-12-20 06:13:30

问题


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();
}

回答1:


You must use an istringstream, not an ifstream.



来源:https://stackoverflow.com/questions/20639889/get-each-value-from-a-string-via-stdifstream

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!