I want to get the numpunct<char> facet for the native locale. I can generate a native locale object by constructing an object with an empty string std::locale native_loc("")
, but once I have it how do I get a numpunct
from it? The documentation I've found doesn't really show the connection between the two.
A facet is an object which can be stored in a locale and retrieved from the locale based on its type. Facets encapsulate data about cultural and language dependencies. They also contain services (functions) that use the encapsulated data to help you internationalize your programs.
The std::locale class keeps reference counters on installed facets and can be efficiently copied. You can also create your own facets and install them into existing locale objects. For example: class measure : public std::locale::facet { public: typedef enum { inches, ... }
An object of class std::locale is an immutable indexed set of immutable facets. Each stream object of the C++ input/output library is associated with an std::locale object and uses its facets for parsing and formatting of all data. In addition, a locale object is associated with each std::basic_regex object.
Use use_facet<facet_type>(locale)
:
std::numpunct<char> const&n = std::use_facet< std::numpunct<char> >(std::locale(""));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With