fuad_cs22

String Tokenizer

Jan 24th, 2021
491
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. /*
  5. Fuad Hasan
  6. */
  7. std::vector<std::string> scan(std::string& str, char token)
  8. {
  9.     std::vector<std::string> tokenstr;
  10.     int x = 0;
  11.     for(int i = 0; i < str.length(); i++)
  12.     {
  13.         if(str[i] == token)
  14.         {
  15.             tokenstr.push_back("");
  16.             x++;
  17.         }
  18.         else{
  19.             tokenstr[x] += str[i];
  20.         }
  21.     }
  22.     return tokenstr;
  23. }
  24.  
  25. int main()
  26. {
  27.     std::string str = "Hello world. Hello Human. Nice to see you";
  28.     std::vector<std::string> p = scan(str, '.');
  29.     for(auto& i : p)
  30.     {
  31.         std::cout << i << std::endl;
  32.     }
  33.     std::cin.get();
  34. }
RAW Paste Data