从句子中删除第一个单词并将其存储在 C++ 中

Removing the first word from a sentence and store it c++

我正在用 C++ 读取一个文件,我想删除除第一个单词以外的所有单词并存储它,

sentence = sentence.substr(sentence.find_first_of(" \t") + 
1);

此代码删除第一个单词并保留整个句子,有没有办法存储删除的单词。

https://en.cppreference.com/w/cpp/string/basic_string/find_first_of 从 find_first_of 获取第一个匹配项的位置,然后从 find_first_of

获取句子开始位置

std::string w1 = sentence.substr(0, sentence.find_first_of(" \t"));