1 | #include <iostream>
|
---|
2 | #include <boost/locale.hpp>
|
---|
3 |
|
---|
4 | using namespace boost::locale;
|
---|
5 |
|
---|
6 | int main()
|
---|
7 | {
|
---|
8 | generator gen;
|
---|
9 | // Create locale generator
|
---|
10 | std::locale::global(gen("ru_RU.CP1251"));
|
---|
11 |
|
---|
12 | const unsigned char mas[]={0xCF, 0xF0, 0xE8, 0xE2, 0xE5, 0xF2, 0x00}; /// Russian "Ïðèâåò" in CP1251 codepage
|
---|
13 |
|
---|
14 | const char* strHello=(const char*)mas;
|
---|
15 | //const char* strHello="Ïðèâåò";
|
---|
16 |
|
---|
17 |
|
---|
18 | // Display a trash. But I think it's a good - I do not set locale
|
---|
19 | std::cout<<strHello<<std::endl;
|
---|
20 |
|
---|
21 | // set system default locale (by Boost.Locale method)
|
---|
22 | std::locale::global(gen(""));
|
---|
23 |
|
---|
24 | // Display a trash.
|
---|
25 | std::cout<<strHello<<std::endl;
|
---|
26 |
|
---|
27 | // maybe I chose wrong locale?
|
---|
28 | // Let us try to find it!
|
---|
29 |
|
---|
30 |
|
---|
31 | // ru_RU.CP1251
|
---|
32 | std::locale::global(gen("ru_RU.CP1251"));
|
---|
33 |
|
---|
34 | // Display a trash.
|
---|
35 | std::cout<<strHello<<std::endl;
|
---|
36 |
|
---|
37 | // ru_RU.CP866
|
---|
38 | std::locale::global(gen("ru_RU.CP866"));
|
---|
39 |
|
---|
40 | // Display a trash.
|
---|
41 | std::cout<<strHello<<std::endl;
|
---|
42 |
|
---|
43 | // ru_RU.UTF-8
|
---|
44 | std::locale::global(gen("ru_RU.UTF-8"));
|
---|
45 |
|
---|
46 | // Display a trash.
|
---|
47 | std::cout<<strHello<<std::endl;
|
---|
48 |
|
---|
49 |
|
---|
50 | // dumb idea
|
---|
51 | std::locale::global(gen("brainfuck"));
|
---|
52 |
|
---|
53 | // Display a trash.
|
---|
54 | std::cout<<strHello<<std::endl;
|
---|
55 |
|
---|
56 |
|
---|
57 | // My brain need to reeboot!
|
---|
58 | // Totally WRONG LOCALE "brainfuck" was created and applied!!!!
|
---|
59 |
|
---|
60 | // and finally!!!
|
---|
61 |
|
---|
62 | // set system default locale (by Windows method)
|
---|
63 | std::locale::global( std::locale("") );
|
---|
64 |
|
---|
65 | // Looking good!
|
---|
66 | std::cout<<strHello<<std::endl;
|
---|
67 |
|
---|
68 | // --- I have new idea - try using imbue --------------------------------
|
---|
69 |
|
---|
70 | // using Some "default" locale
|
---|
71 | std::locale::global( std::locale("English") );
|
---|
72 |
|
---|
73 | // Display Trash2
|
---|
74 | std::cout<<strHello<<std::endl;
|
---|
75 |
|
---|
76 | std::locale loc=gen("ru_RU.CP1251");
|
---|
77 |
|
---|
78 | std::cout.imbue(loc);
|
---|
79 |
|
---|
80 | // Display Trash2
|
---|
81 | std::cout<<strHello<<std::endl;
|
---|
82 |
|
---|
83 | loc=gen("ru_RU.CP866");
|
---|
84 |
|
---|
85 | std::cout.imbue(loc);
|
---|
86 |
|
---|
87 | // Display Trash2
|
---|
88 | std::cout<<strHello<<std::endl;
|
---|
89 | }
|
---|