Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a facet from a std::locale object?

Tags:

c++

locale

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.

like image 908
Mark Ransom Avatar asked Mar 04 '10 18:03

Mark Ransom


People also ask

What is a locale facet?

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.

What does std:: locale do?

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, ... }

What is locale in C++?

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.


1 Answers

Use use_facet<facet_type>(locale):

std::numpunct<char> const&n = std::use_facet< std::numpunct<char> >(std::locale(""));
like image 151
Johannes Schaub - litb Avatar answered Oct 09 '22 23:10

Johannes Schaub - litb