How to format a number with thousands separator in C/C++
问题 I am trying to do this simple task. Just to format a number using C or C++, but under Windows CE programming. In this environment, neither inbue nor setlocale methods work. Finally I did this with no success: char szValue[10]; sprintf(szValue, "%'8d", iValue); Any idea? 回答1: Here's one way - create a custom locale and imbue it with the appropriately customised facet: #include <locale> #include <iostream> #include <memory> struct separate_thousands : std::numpunct<char> { char_type do