fork download
  1. #include <string>
  2. #include <iostream>
  3. #include <regex>
  4. using namespace std;
  5.  
  6. int main() {
  7. std::vector<std::string> strings;
  8. std::string s = "word1; word2 ; word31 word32";
  9. std::regex re(R"(\s*;\s*)");
  10. std::regex_token_iterator<std::string::iterator> it(s.begin(), s.end(), re, -1);
  11. decltype(it) end{};
  12. while (it != end){
  13. strings.push_back(*it++);
  14. }
  15. for (auto& s: strings){ //std::cout << strings[strings.size()-1] << std::endl;
  16. std::cout << "'" << s << "'" << std::endl;
  17. }
  18. return 0;
  19. }
  20.  
Success #stdin #stdout 0s 15344KB
stdin
Standard input is empty
stdout
'word1'
'word2'
'word31 word32'