fork download
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <iomanip>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. int main(int argc, const char * argv[])
  10. {
  11. {
  12. vector<string> v;
  13. string s = "xxxxxxxxxxxxxxxxxx|yyyyyyyyyyyyyyyyyy|zzzzzzzzzzzzzzzzzz";
  14. for(char * c = strtok((char*)s.data(),"|"); c; c = strtok(nullptr,"|"))
  15. v.push_back(c);
  16.  
  17. for(auto t: v) cout << t << endl;
  18. }
  19. {
  20. vector<string> v;
  21. string s = "xxxxxxxxxxxxxxxxxx|yyyyyyyyyyyyyyyyyy|zzzzzzzzzzzzzzzzzz";
  22.  
  23. size_t b = 0; // Очередная подстрока
  24. for(size_t e = s.find('|',b); e != s.npos; e = s.find('|',++b))
  25. {
  26. v.push_back(s.substr(b,e-b));
  27. b = e;
  28. }
  29. v.push_back(s.substr(b));
  30.  
  31. for(auto t: v) cout << t << endl;
  32. }
  33. }
  34.  
Success #stdin #stdout 0s 4380KB
stdin
Standard input is empty
stdout
xxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyy
zzzzzzzzzzzzzzzzzz
xxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyy
zzzzzzzzzzzzzzzzzz