I have a very complicated code, with many outputs which are print out on a text file, now I want to use thousand separator for numbers?
how should I do this?
Here is a subroutine that displays your numbers with commas, though it doesn't display anything after the point, so the above example would show only 1,234,567. Hope that's enough.
Keep in mind that messing with locales is a system-dependent thing, especially on Windows. Cubbi's code, for example, will not work with GCC out of the box.
This is the frustrating about the C++ locale specification -- it leaves the names of locales to implementation. Sure, there are reasons that it was done that way, but I think it was a mistake. (It would take very little to specify a standard that could be mapped to individual implementations...)