Old thread, but anyway ... One should be aware that using a std::locale
makes the string "pretty", complete with correct decimal point, thousands separators and what not, depending on the platform and locale. Most probably, using imbue()
will break any parsing of the string after it's formatted. For example:
std::ostringstream s;
std::locale l("fr-fr");
s << "without locale: " << 1234.56L << std::endl;
s.imbue(l);
s << "with fr locale: " << 1234.56L << std::endl;
std::cout << s.str();
Gives the following output:
without locale: 1234.56
with fr locale: 1 234,56
Using strtod()
or similar on the second string probably won't work very well ... Also, the space between "1" and "2" in the second output string is a non-breaking one, making the string even prettier :-)