Disable commas in cout?

In the project I'm working on now, I refer to a proprietary dynamic library. As soon as I start the initialize library, the behavior of writing and printing numbers changes.

Commas were inserted in every third decimal digit. Those..

 cout << 123456789 << endl 

used to print 123456789 , and now it prints 123,456,789 . This is terribly annoying because this behavior is not what I want.

After some research, I suspect the problem is localized. I tried to use this line of code after calling the initialize function

 setlocale(LC_ALL,"C"); 

thinking that he can reset my local by default; but to no avail. Commas are saved!

What am I missing?

I posted the following related question on here .

+7
source share
2 answers

You can set the locale for the stream, regardless of the locale set using setlocale . Try std::cout.imbue(std::locale("C"));

+5
source

If you just want to get rid of commas, you can also replace the current std::numpunct , which probably causes it to default, which does not override do_grouping .

 std::cout.imbue(std::locale(std::cout.getloc(), new std::numpunct<char>())); 
+2
source

All Articles