imbue()
the output stream with a locale that has the desired separator. For example:
#include <iostream>
#include <locale>
int main()
{
// imbue the output stream with a locale.
int i = 45749785;
std::cout << i << "\n";
std::cout.imbue(std::locale(""));
std::cout << i << "\n";
}
Output on my machine (and online demo):
45749785 45,749,785
As commented, and answered, by James Kanze imbue the input stream also to read the separated int
values without manually modifying the input.
See Stroustrop's Appendix D: Locales for a detailed overview of locales.