fork(4) download
  1. #include <string>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <regex>
  5. #include <vector>
  6.  
  7. std::regex operator ""_re (char const* const str, std::size_t) {
  8. return std::regex{str};
  9. }
  10.  
  11. std::vector<std::string> split(const std::string& text, const std::regex& re) {
  12. const std::vector<std::string> parts(
  13. std::sregex_token_iterator(text.begin(), text.end(), re, -1),
  14. std::sregex_token_iterator());
  15. return parts;
  16. }
  17.  
  18. int main() {
  19. const std::vector<std::string> parts = split("Quick brown fox.", "\\s+"_re);
  20. std::copy(parts.begin(), parts.end(),
  21. std::ostream_iterator<std::string>(std::cout, "\n"));
  22. return 0;
  23. }
Success #stdin #stdout 0s 3560KB
stdin
Standard input is empty
stdout
Quick
brown
fox.