std::use_facet - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::use_facet

From cppreference.com
< cpp‎ | locale

Defined in header `<locale>` |  |
template< class Facet > const Facet& use_facet( const std::locale& loc ); |  |

Obtains a reference to a facet implemented by `loc`.

### [edit] Parameters

loc | - | the locale object to query

### [edit] Return value

Returns a reference to the facet. The reference returned by this function is valid as long as any std::locale object exists that implements `Facet`.

### [edit] Exceptions

std::bad_cast if std::has_facet<Facet>(loc) == false.

### [edit] Example

Display the 3-letter currency name used by the user's preferred locale

Run this code

    #include <iostream>
    #include <locale>

    int main()
    {
        std::locale loc = std::locale(""); // user's preferred locale
        std::cout << "Your currency string is "
                  << std::use_facet<std::moneypunct<char, true>>(loc).curr_symbol() << '\n';
    }

Output:

    Your currency string is USD

### [edit] See also

locale | set of polymorphic facets that encapsulate cultural differences (class) [edit]
has_facet | checks if a locale implements a specific facet (function template) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/locale/use_facet&oldid=75055"