要从流中读取单词,请在字符串上使用operator >>
std::stringstream stream("I am working as a nurse.");
std::string word;
stream >> word; // word now holds 'I'
stream >> word; // word now holds 'am'
stream >> word; // word now holds 'working'
// .. etc
Run Code Online (Sandbox Code Playgroud)