fork(5) download
  1. #include <iostream>
  2. #include <regex>
  3. #include <sstream>
  4. #include <string>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. int main() {
  9. string item{"text1,tex2,blah,"};
  10. regex re{"((?:[^\\\\,]|\\\\.)*?)(?:,|$)"};
  11. vector<string> m_vecFields{sregex_token_iterator(item.begin(), item.end(), re, 1), sregex_token_iterator()};
  12.  
  13. for(const auto& i : m_vecFields) cout << "- " << i << endl;
  14. return 0;
  15. }
Success #stdin #stdout 0s 3548KB
stdin
Standard input is empty
stdout
- text1
- tex2
- blah
-