Apache C++ Standard Library Reference Guide

## use_facet()

Library: Localization

    Function

- Local Index
- Summary
- Synopsis
- Description
- Example
- See Also
- Standards Conformance

### Local Index

No Entries

### Summary

A template function used to obtain a facet from a specific locale

### Synopsis

    #include <locale>

    namespace std {
      template<class Facet> const Facet& use_facet(const locale&);
    }

### Description

`use_facet()` returns a reference to the corresponding facet contained in the `locale` argument. You specify the facet type by explicitly including the template parameter (see the example below). If that facet is not present, then `use_facet()` throws bad_cast. Otherwise, the reference remains valid for as long as any copy of the locale exists.

### Example

    //
    //  usefacet.cpp
    //

    #include <iostream>

    int main () {

      std::locale loc;

      // Get a ctype facet
      const std::ctype<char>&
          ct = std::use_facet<std::ctype<char> >(loc);

      std::cout << 'a' << ct.toupper('c') << std::endl;

      return 0;
    }

    Program Output:

    aC

### See Also

locale, Facets, `has_facet()`

### Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 22.1.1