user2976089
user2976089

Reputation: 355

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

Upvotes: 0

Views: 197

Answers (1)

Medinoc
Medinoc

Reputation: 6608

You must use an istringstream, not an ifstream.

Upvotes: 5

Related Questions