Question

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. Ie.

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.

After some research I suspect a locale issue. I have tried using this line of code after calling the initialize function

setlocale(LC_ALL,"C");

thinking it might reset my local to the default; but to no avail. The commas persist!!

What am I missing?

I have posted a related follow on question here.

Was it helpful?

Solution

You can set the locale for a stream, independent of the locale that's set with setlocale. Try std::cout.imbue(std::locale("C"));

OTHER TIPS

If you just want to get rid of the commas, you could also replace the current std::numpunct which is probably causing it with the default one which does not override do_grouping.

std::cout.imbue(std::locale(std::cout.getloc(), new std::numpunct<char>()));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top