Y
year1943
There was the same topic not so long ago, but as I see it stays w/o
answer:
http://groups.google.ru/group/comp....&q=locale+imbue&rnum=1&hl=ru#fe109c899f916871
As Bjarne Stroustrup said in his book,
"in Stroustrup (retranslated from German)
"Setting the global locale does not affect existing input/output
streams. The streams continue to use those locales that were assigned
to
them using imbue() during their creation." "
But actually I see quite the opposite behaviour.
The following code:
#include <iostream>
// #include <clocale>
#include <locale>
int main() {
std::locale loc("") ;
// std::setlocale(LC_ALL, "") ; // (1)
std::locale::global(loc) ; // (2)
// std::wcout.imbue(loc) ; // (3)
std::wcout << L"(non-ASCII national letters here)" << std::endl ;
std::wstring wstr ;
std::wcin >> wstr ;
std::wcout << L'[' << wstr << L']' << std::endl ;
return 0 ;
}
DOES work (it correctly inputs and outputs non-ASCII, non-"C"-locale
chars), while it SHOULD NOT (?), and if you commented out (1) and (2)
and uncommented (3) - it DOESN'T work, though it SHOULD DO (as
Stroustrup says).
More over, if you switch global locale between points of wcout usage,
like:
int main() {
std::locale loc("") ;
std::wcout << L"(non-ASCII national letters here)" << std::endl ;
std::locale::global(loc) ; // (2)
std::wcout << L"(non-ASCII national letters here)" << std::endl ;
- wcout DOESN'T WORK correctly even after global locale switch!!!
What's wrong with my attempts to make it work??
(I'm afraid, it's one more of numerous problems/bugs of C/C++
alliance, but would happy to hear "official" answer and ways to
workaround...)
answer:
http://groups.google.ru/group/comp....&q=locale+imbue&rnum=1&hl=ru#fe109c899f916871
As Bjarne Stroustrup said in his book,
"in Stroustrup (retranslated from German)
"Setting the global locale does not affect existing input/output
streams. The streams continue to use those locales that were assigned
to
them using imbue() during their creation." "
But actually I see quite the opposite behaviour.
The following code:
#include <iostream>
// #include <clocale>
#include <locale>
int main() {
std::locale loc("") ;
// std::setlocale(LC_ALL, "") ; // (1)
std::locale::global(loc) ; // (2)
// std::wcout.imbue(loc) ; // (3)
std::wcout << L"(non-ASCII national letters here)" << std::endl ;
std::wstring wstr ;
std::wcin >> wstr ;
std::wcout << L'[' << wstr << L']' << std::endl ;
return 0 ;
}
DOES work (it correctly inputs and outputs non-ASCII, non-"C"-locale
chars), while it SHOULD NOT (?), and if you commented out (1) and (2)
and uncommented (3) - it DOESN'T work, though it SHOULD DO (as
Stroustrup says).
More over, if you switch global locale between points of wcout usage,
like:
int main() {
std::locale loc("") ;
std::wcout << L"(non-ASCII national letters here)" << std::endl ;
std::locale::global(loc) ; // (2)
std::wcout << L"(non-ASCII national letters here)" << std::endl ;
- wcout DOESN'T WORK correctly even after global locale switch!!!
What's wrong with my attempts to make it work??
(I'm afraid, it's one more of numerous problems/bugs of C/C++
alliance, but would happy to hear "official" answer and ways to
workaround...)