#include <iostream>
#include <sstream>
#include <string>
int main()
{
{
std::istringstream stm( "one two three four bad " ) ;
std::string word ;
int n = 0 ;
while( !stm.eof() ) // bad
{
stm >> word ;
std::cout << ++n << ". " << word << '\n' ;
}
}
std::cout << "----------------------\n" ;
{
std::istringstream stm( "one two three four good " ) ;
std::string word ;
int n = 0 ;
while( stm >> word ) // good
std::cout << ++n << ". " << word << '\n' ;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KCmludCBtYWluKCkKewogICAgewogICAgICAgIHN0ZDo6aXN0cmluZ3N0cmVhbSBzdG0oICJvbmUgdHdvIHRocmVlIGZvdXIgYmFkICIgKSA7CiAgICAgICAgc3RkOjpzdHJpbmcgd29yZCA7CiAgICAgICAgaW50IG4gPSAwIDsKICAgICAgICB3aGlsZSggIXN0bS5lb2YoKSApIC8vIGJhZAogICAgICAgIHsKICAgICAgICAgICAgIHN0bSA+PiB3b3JkIDsKICAgICAgICAgICAgIHN0ZDo6Y291dCA8PCArK24gPDwgIi4gIiA8PCB3b3JkIDw8ICdcbicgOwogICAgICAgIH0KICAgIH0KCiAgICBzdGQ6OmNvdXQgPDwgIi0tLS0tLS0tLS0tLS0tLS0tLS0tLS1cbiIgOwoKICAgIHsKICAgICAgICBzdGQ6OmlzdHJpbmdzdHJlYW0gc3RtKCAib25lIHR3byB0aHJlZSBmb3VyIGdvb2QgIiApIDsKICAgICAgICBzdGQ6OnN0cmluZyB3b3JkIDsKICAgICAgICBpbnQgbiA9IDAgOwogICAgICAgIHdoaWxlKCBzdG0gPj4gd29yZCAgKSAvLyBnb29kCiAgICAgICAgICAgIHN0ZDo6Y291dCA8PCArK24gPDwgIi4gIiA8PCB3b3JkIDw8ICdcbicgOwogICAgfQp9Cg==