I am reading from a file in C , and I want to remove all but the first word and store it,
sentence = sentence.substr(sentence.find_first_of(" \t")
1);
this code remove the first word and keep the whole sentence , is there a way to store the removed word.
CodePudding user response:
https://en.cppreference.com/w/cpp/string/basic_string/find_first_of take position of first match from find_first_of and then sentence start pos to position from find_first_of
std::string w1 = sentence.substr(0, sentence.find_first_of(" \t"));