Advertisement
obernardovieira

Another split string

Aug 11th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. std::vector<std::string> split(std::string source, std::string delimiter) {
  6.     std::vector<std::string> tmp;
  7.     size_t start = 0, end = 0;
  8.    
  9.     while((end = source.find(delimiter, start)) != std::string::npos) {
  10.         tmp.push_back(source.substr(start, end - start));
  11.         start = end + 1;
  12.     }
  13.     tmp.push_back(source.substr(start, source.length()));
  14.     return tmp;
  15. }
  16.  
  17. int main() {
  18.    
  19.     std::vector<std::string> d = split("ja vai embora", " ");
  20.    
  21.     for(int z=0; z!=d.size(); z++) {
  22.         std::cout << d.at(z) << std::endl;
  23.     }
  24.    
  25.    
  26.     std::cout << "Hello World" << std::endl;
  27.    
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement