通过 std::ifstream 从字符串中获取每个值

Get each value from a string via std::ifstream

本文关键字:获取 字符串 std ifstream 通过      更新时间:2023-10-16

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

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

你必须使用istringstream,而不是ifstream