HP C++ User Documentation


use_facet (3C++std) - Tru64 UNIX

Standard C++ Library
Copyright 1996, Rogue Wave Software, Inc.


  use_facet - Template function used to obtain a facet.


  #include <locale>
  template <class Facet> const Facet& use_facet(const locale&);


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

  Note that if your compiler cannot overload function templates on return
  type then you'll need to use an alternate use_facet template.  The
  alternate template takes an additional argument that's a pointer to the
  type of facet you want to extract from the locale.  The declaration looks
  like this:

  template <class Facet>
  const Facet& use_facet(const locale&, Facet*);

  The example below shows the use of both variations of use_facet.


  // usefacet.cpp
  #include <iostream>

  int main ()
   using namespace std;

   locale loc;

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

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

   return 0;


  locale, facets, has_facet

About PDF files: The PDF files on this site can be read online or printed using Adobe® Acrobat® Reader. If you do not have this software on your system, you may download it from Adobe's website.
Privacy statement Using this site means you accept its terms C++ support
© 2008 Hewlett-Packard Development Company, L.P.