In a project I am currently working on I link to a proprietary dynamic library. As soon as I run the library's initialize function, the behavior of logging and printing of numbers changes.
Commas have been inserted at every third decimal. i.e.
cout << 123456789 << endl
used to print out 123456789
and now it prints 123,456,789
. This is horribly annoying, because this behavior is not what I want.
This issue is not only apparent in the binary I am compiling, but also shows up in all the couts
and stringstreams
in the libraries that I link to it.
I have tried using this line of code after calling the initialize function:
setlocale(LC_ALL,"C");
thinking it might reset my locale to the default but to no avail. The commas persist!
This snippet of code:
std::cout.imbue(std::locale("C"));
works to reset the locale of couts
and every stringstream
I apply it too. However, do I really need to call imbue
on EVERY stringstream
declared in EVERY library I link to? There are some libraries that are proprietary and I cannot actually change their source code.
There must be a way to reset the locale back to "C"
globally?
locale::global
(as indicated in the linked page) only affect the streams constructed after the call. So,cin
,cout
,cerr
and other streams are not imbued with the global locale, one must do that manually; – Howell