All Locale and Facet Facilities
All Locale and Facet Facilities
A compact scan page for locale objects, classic facet categories, and locale-aware text and numeric processing facilities.
All Locale and Facet Facilities
A compact scan page for locale objects, classic facet categories, and locale-aware text and numeric processing facilities.
Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.
std::localectypenumpunctnum_get, num_putcollatetime_get, time_putmoney_get, money_putmessages#include <locale>
#include <sstream>
struct comma_punct : std::numpunct<char> {
char do_thousands_sep() const override { return ','; }
std::string do_grouping() const override { return "\3"; }
};
int main() {
std::ostringstream out;
out.imbue(std::locale{std::locale::classic(), new comma_punct});
out << 1234567;
}
The point is not to memorize facet internals. The point is to remember that locale behavior comes from an explicit locale object, which you can imbue into a stream instead of relying on hidden global settings.
std::locale and the stream or parser you are actually using#include <locale>
#include <sstream>
struct comma_punct : std::numpunct<char> {
char do_thousands_sep() const override { return ','; }
std::string do_grouping() const override { return "\3"; }
};
int main() {
std::ostringstream out;
out.imbue(std::locale{std::locale::classic(), new comma_punct});
out << 1234567;
return out.str() == "1,234,567" ? 0 : 1;
}