Advertisement
giGii

why

Aug 3rd, 2022
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. vector<string> SplitIntoWords(const string& text) {
  9.     vector<string> words;
  10.     string word;
  11.     for (const char& c : text) {
  12.         if (c == ' ') {
  13.             if (!word.empty()) {
  14.                 words.push_back(word);
  15.                 word.clear();
  16.             }
  17.         } else {
  18.             word += c;
  19.         }
  20.     }
  21.     if (!word.empty()) {
  22.         words.push_back(word);
  23.     }
  24.  
  25.     return words;
  26. }
  27.  
  28. int main() {
  29.     // string initial_text = "test search query"s;
  30.     vector<string> v = SplitIntoWords("test search query"s);
  31.     for (const string& s : v) {
  32.         cout << '[' << s << ']' << endl;
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement