Реализуйте и протестируйте Cvt_to_upper (параграф D.4).
Ладно эту тему также на потом отложим, я просто набрал код тот что в книге, ну конечно он ничего не работает.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#include <iostream> using std::cout; using std::endl; using std::cin; #include <locale> using std::locale; using std::codecvt; class Cvt_to_upper:public codecvt<char,char,mbstate_t> { explicit Cvt_to_upper(size_t r=0):codecvt(r){} protected: typedef state_type State; //читаем внешнее представление пишем внутреннее: result do_in(State& s,const char* from_end, const char*& from_next, char* to, char* to_end, char*& to_next)const; //читаем внутреннее представление пишем внешнее result do_out(State& s,const char* from, const char* from_end, const char*& from_next, char* to, char* to_end, char*& to_next)const { return codecvt<char,char,mbstate_t>::do_out (s,from,from_end,from_next,to,to_end,to_next); } result do_unshift(State&, E* to, E* to_end, E* to_next)const {return ok;} int do_encoding()const throw(){return 1;} bool do_always_noconv()const throw(){return false;} int do_length(const State&, const E* from, const E* from_end, size_t max)const; int do_max_length()const throw(); }; codecvt<char,char,mbstate_t>::result Cvt_to_upper::result do_in(State& s,const char* from_end, const char*& from_next, char* to, char* to_end, char*& to_next)const; { //тут ее нужно самому реализовать } int main() { locale ulocale(locale(),new Cvt_to_upper); cin.imbue(ulocale); char ch; while(cin >>ch)cout <<ch; cout <<endl; return 0; } |
[youtube]https://www.youtube.com/watch?v=Ggd8_B39zeM[/youtube]