fork download
  1. #include <string>
  2. #include <vector>
  3. #include <iostream>
  4. int main()
  5. {
  6. std::string str = "hello,world";
  7. std::vector<std::string> vct;
  8. std::size_t pos = str.find(',');
  9. if(pos != std::string::npos)
  10. {
  11. ++pos;
  12. vct.push_back(str.substr(0, pos));
  13. vct.push_back(str.substr(pos));
  14. std::cout << vct[0] << '\n' << vct[1] << '\n';
  15. }
  16. else
  17. {
  18. std::cout << "No commas in your string\n";
  19. }
  20.  
  21. }
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout
hello,
world