0

How do I break a sentence in c++ down into smaller strings

30th Oct 2020, 12:51 PM
Bharadwaaja Kanakadandi
Bharadwaaja Kanakadandi - avatar
2 odpowiedzi
+ 2
You can use either the find() or the find_first_of() method to search for delimitation points, depending on whether you are looking for strings or characters: https://en.cppreference.com/w/cpp/string/basic_string/find https://en.cppreference.com/w/cpp/string/basic_string/find_first_of The methods will return an index you can then use to construct a substring from the start of the string or from the last index: https://en.cppreference.com/w/cpp/string/basic_string/substr You can store those substrings in a vector: https://en.cppreference.com/w/cpp/container/vector If you are splitting by whitespace characters only, you can instead use a "stringstream" wrapper to simplify this: https://en.cppreference.com/w/cpp/io/basic_istringstream Here is an example by another user: https://code.sololearn.com/cxr6SqIQOPGi/?ref=app Here are similar threads: https://www.sololearn.com/discuss/2156455/?ref=app https://www.sololearn.com/discuss/1565370/?ref=app https://www.sololearn.com/discuss/2483099/?ref=app
30th Oct 2020, 1:23 PM
Shadow
Shadow - avatar