[boost.multiprecision] print cpp_int with a thousands separator
Dear List, how can I control the thousands separator behavior when streaming a cpp_int to std::cout? I think it is not possible without changing the global locale, as cpp_int.str uses lexical_cast, which uses the global locale object to read the thousands separator character. This prevents me from having a custom formatting like below. Is there another way? Best, Tassilo #include <iostream> #include <locale> #include <iomanip> int main() { struct my_numpunct : std::numpunct<char> { protected : virtual char do_thousands_sep() const override { return '.' ; } virtual std::string do_grouping() const override { return "\03" ; } }; cpp_int testNum(1000); std::cout.imbue( std::locale( std::cout.getloc(), new my_numpunct ) ) ; std::cout << testNum << '\n' ; // still get 1000, desired is 1.000 }
participants (1)
-
Tassilo Glander