fork download
  1. #include <locale>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <iterator>
  5. #include <vector>
  6. #include <sstream>
  7.  
  8. class my_ctype : public
  9. std::ctype<char>
  10. {
  11. mask my_table[table_size];
  12. public:
  13. my_ctype(size_t refs = 0)
  14. : std::ctype<char>(&my_table[0], false, refs)
  15. {
  16. std::copy_n(classic_table(), table_size, my_table);
  17. my_table['-'] = (mask)space;
  18. my_table['\''] = (mask)space;
  19. }
  20. };
  21.  
  22. // And a little test program to show it works:
  23.  
  24. int main() {
  25. std::istringstream input("This is some input from McDonald's and Burger-King.");
  26. std::locale x(std::locale::classic(), new my_ctype);
  27. input.imbue(x);
  28.  
  29. std::copy(std::istream_iterator<std::string>(input),
  30. std::istream_iterator<std::string>(),
  31. std::ostream_iterator<std::string>(std::cout, "\n"));
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 2968KB
stdin
Standard input is empty
stdout
This
is
some
input
from
McDonald
s
and
Burger
King.