fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <vector>
  4. #include <string>
  5. #include <iterator>
  6. using namespace std;
  7.  
  8. struct tokens: std::ctype<char>
  9. {
  10. tokens(): std::ctype<char>(get_table()) {}
  11.  
  12. static std::ctype_base::mask const* get_table()
  13. {
  14. typedef std::ctype<char> cctype;
  15. static const cctype::mask *const_rc= cctype::classic_table();
  16.  
  17. static cctype::mask rc[cctype::table_size];
  18. memcpy(rc, const_rc, cctype::table_size * sizeof(cctype::mask));
  19.  
  20. rc[','] = std::ctype_base::space;
  21. rc[' '] = std::ctype_base::space;
  22. return &rc[0];
  23. }
  24. };
  25.  
  26.  
  27. int main() {
  28.  
  29.  
  30.  
  31.  
  32.  
  33. std::string s = "right way, wrong way, correct way";
  34. std::stringstream ss(s);
  35. ss.imbue(std::locale(std::locale(), new tokens()));
  36. std::istream_iterator<std::string> begin(ss);
  37. std::istream_iterator<std::string> end;
  38. std::vector<std::string> vstrings(begin, end);
  39. std::copy(vstrings.begin(), vstrings.end(),
  40. std::ostream_iterator<std::string>(std::cout, "\n"));
  41.  
  42. return 0;
  43. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In static member function ‘static const mask* tokens::get_table()’:
prog.cpp:18:71: error: ‘memcpy’ was not declared in this scope
         memcpy(rc, const_rc, cctype::table_size * sizeof(cctype::mask));
                                                                       ^
stdout
Standard output is empty