Advertisement
HwapX

Split C++

Mar 3rd, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <string>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. vector<string> split(string str, char delimiter = ' ')
  7. {
  8.     vector<string> ret;
  9.    
  10.     int start = 0;
  11.    
  12.     for(int i=0; i < str.length(); ++i) {
  13.         if(str[i] == delimiter) {
  14.             ret.push_back(str.substr(start, i-start));
  15.             start = i+1;
  16.         }
  17.     }
  18.    
  19.     ret.push_back(str.substr(start, start - str.length()));
  20.    
  21.     return ret;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement