Search code examples
c++getstdifstream

Get each value from a string via std::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();
}

Solution

  • You must use an istringstream, not an ifstream.