> (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...)
It seems (partially) right. Call to
std::ios_base::sync_with_stdio(false) ;
at the every beginning changes behaviour, but it still stays looking
buggy or "impl defined":
int main() {
std::ios_base::sync_with_stdio(false) ;
std::locale loc("") ;
std::wcout << L"Hello world!" << std::endl ;
std::wcout.imbue(loc) ;
std::wcout << L" !" << std::endl ;
this works fine, as expected.
If you try to output non-ASCI chars with "C" locale on stream:
std::wcout << L" !" << std::endl ;
nothing is printed at all, even with flushing endl manip; following
even ASCII strings also disappears silently to blackhole;
but if later you call imbue:
std::wcout << L" !" << std::endl ;
std::wcout.imbue(loc) ;
than you got -
terminate called after throwing an instance of
'std::ios_base::failure'
what(): basic_filebuf::_M_convert_to_external conversion error
Aborted
It seems changing the global locale now doesn't affect stream:
int main() {
std::ios_base::sync_with_stdio(false) ;
std::locale loc("") ;
std::wcout << L"Hello world!" << std::endl ;
std::locale::global(loc) ;
// std::wcout << L" !" << std::endl ; // will cause
exception
std::wcout.imbue(loc) ;
std::wcout << L" !" << std::endl ; // now OK
std::locale::global(std::locale::classic()) ;
std::wcout << L" !" << std::endl ; // OK, using
stream's loc not global
std::wcout.imbue(std::locale::classic()) ;
// std::wcout << L" !" << std::endl ; // will cause
exception
std::wcout << L"Hello world!" << std::endl ; // OK
Either Bjarne was inaccurate or at least not pedantic with his locale/
stream descriptions... or libstdc++ is implemented in a such manner?..