fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <locale>
  4. #include <sstream>
  5.  
  6. struct ctype_russian : std::ctype<char>
  7. {
  8. static const mask* make_table()
  9. {
  10. static std::vector<mask> v{classic_table(), classic_table() + table_size};
  11. for(char c: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") {
  12. v[(unsigned char)c] &= ~alpha;
  13. v[(unsigned char)c] |= space;
  14. }
  15. for(char c: "абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ") {
  16. v[(unsigned char)c] |= alpha;
  17. v[(unsigned char)c] &= ~space;
  18. }
  19. return &v[0];
  20. }
  21. ctype_russian(std::size_t refs = 0) : ctype(make_table(), false, refs) {}
  22. };
  23.  
  24. int main()
  25. {
  26. std::string in = "English words Русские слова English again";
  27. std::istringstream s(in);
  28. s.imbue(std::locale(s.getloc(), new ctype_russian()));
  29. std::string token;
  30. while (s >> token)
  31. std::cout << " " << token << '\n';
  32. }
  33.  
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
  Русские
  слова