Tests if a particular facet is stored in a specified locale.

template<class Facet>   bool has_facet(      const locale& _Loc   );


The locale to be tested for the presence of a facet.

true if the locale has the facet tested for; false if it does not.

The template function is useful for checking whether nonmandatory facets are listed in a locale before use_facet is called to avoid the exception that would be thrown if it were not present.

// locale_has_facet.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>
using namespace std;

int main( )
   locale loc ( "German_Germany" );
   bool result = has_facet <ctype<char> > ( loc );
   cout << result << endl;


Header: <locale>

Namespace: std

© 2015 Microsoft