Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<string_view> SplitIntoWords(const string& s)
- {
- string_view str = s;
- vector<string_view> result;
- while (true)
- {
- size_t space = str.find(' ');
- result.push_back(str.substr(0,space));
- if (space == str.npos)
- {
- break;
- }
- else
- {
- str.remove_prefix(space+1);
- }
- }
- return result;
- }
- int main()
- {
- for (const string& word : SplitIntoWords(" Red belt C++ "))
- {
- cout << word << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement