fork download
  1.  
  2. #include <iostream>
  3. #include <vector>
  4. #include <string>
  5. #include <sstream>
  6.  
  7.  
  8. using namespace std;
  9.  
  10.  
  11.  
  12.  
  13. std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
  14. std::stringstream ss(s);
  15. std::string item;
  16. while (std::getline(ss, item, delim)) {
  17. elems.push_back(item);
  18. }
  19. return elems;
  20. }
  21.  
  22.  
  23. std::vector<std::string> split(const std::string &s, char delim) {
  24. std::vector<std::string> elems;
  25. split(s, delim, elems);
  26. return elems;
  27. }
  28.  
  29.  
  30. int main() {
  31. std::vector<std::string> extList= split("one:two:abcd:three", ':');
  32.  
  33.  
  34. for( unsigned int i = 0 ; i < extList.size() ; i++)
  35. {
  36. std::cout << extList[i] << "\n";
  37. }
  38.  
  39.  
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
one
two
abcd
three