Freigeben über


<locale> -Funktionen

has_facet
isalnum
isalpha
iscntrl
isdigit
isgraph
islower
isprint
ispunct
isspace
isupper
isxdigit
tolower
toupper
use_facet

has_facet

Testet, ob ein bestimmtes Facet in einem angegebenen Gebietsschema gespeichert wird.

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

Parameter

Loc
Das Gebietsschema, das auf das Vorhandensein eines Facets getestet werden soll.

Rückgabewert

true wenn das Gebietsschema das Facet getestet hat; false wenn dies nicht der Fall ist.

Hinweise

Die Vorlagenfunktion eignet sich zum Prüfen, ob die nicht obligatorischen Facets in einem Gebietsschema aufgeführt sind, bevor use_facet aufgerufen wird, um die Ausnahme zu vermeiden, die ausgelöst werden würde, wenn es nicht vorhanden wäre.

Beispiel

// 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;
}
1

isalnum

Testet, ob ein Element in einem Gebietsschema ein alphabetisches oder ein numerisches Zeichen ist.

template <class CharType>
bool isalnum(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende alphanumerische Element.

Loc
Das Gebietsschema, das das zu testende alphanumerische Element enthält.

Rückgabewert

true wenn das getestete Element alphanumerisch ist; false wenn nicht.

Beispiel

// locale_isalnum.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isalnum ( 'L', loc);
   bool result2 = isalnum ( '@', loc);
   bool result3 = isalnum ( '3', loc);

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "alphanumeric." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not alphanumeric." << endl;

   if ( result2 )
      cout << "The character '@' in the locale is "
           << "alphanumeric." << endl;
   else
      cout << "The character '@' in the locale is "
           << " not alphanumeric." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "alphanumeric." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not alphanumeric." << endl;
}
The character 'L' in the locale is alphanumeric.
The character '@' in the locale is  not alphanumeric.
The character '3' in the locale is alphanumeric.

isalpha

Testet, ob ein Element in einem Gebietsschema ein alphabetisches Zeichen ist.

template <class CharType>
bool isalpha(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende alphabetische Element enthält, welches getestet werden soll.

Rückgabewert

true wenn das getestete Element alphabetisch ist; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: alpha, Ch).

Beispiel

// locale_isalpha.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isalpha ( 'L', loc);
   bool result2 = isalpha ( '@', loc);
   bool result3 = isalpha ( '3', loc);

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "alphabetic." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not alphabetic." << endl;

   if ( result2 )
      cout << "The character '@' in the locale is "
           << "alphabetic." << endl;
   else
      cout << "The character '@' in the locale is "
           << " not alphabetic." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "alphabetic." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not alphabetic." << endl;
}

iscntrl

Testet, ob ein Element in einem Gebietsschema ein Steuerzeichen ist.

template <class CharType>
bool iscntrl(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende Element enthält.

Rückgabewert

true wenn das getestete Element ein Steuerelementzeichen ist; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: cntrl, Ch).

Beispiel

// locale_iscntrl.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = iscntrl ( 'L', loc );
   bool result2 = iscntrl ( '\n', loc );
   bool result3 = iscntrl ( '\t', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a control character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a control character." << endl;

   if ( result2 )
      cout << "The character-set 'backslash-n' in the locale\n is "
           << "a control character." << endl;
   else
      cout << "The character-set 'backslash-n' in the locale\n is "
           << " not a control character." << endl;

   if ( result3 )
      cout << "The character-set 'backslash-t' in the locale\n is "
           << "a control character." << endl;
   else
      cout << "The character-set 'backslash-n' in the locale \n is "
           << " not a control character." << endl;
}

isdigit

Testet, ob ein Element in einem Gebietsschema ein numerisches Zeichen ist.

template <class CharType>
bool isdigit(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende Element enthält.

Rückgabewert

true wenn das getestete Element ein numerisches Zeichen ist; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: digit, Ch).

Beispiel

// locale_is_digit.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isdigit ( 'L', loc );
   bool result2 = isdigit ( '@', loc );
   bool result3 = isdigit ( '3', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a numeric character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a numeric character." << endl;

   if ( result2 )
      cout << "The character '@' in the locale is "
           << "a numeric character." << endl;
   else
      cout << "The character '@' in the locale is "
           << " not a numeric character." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "a numeric character." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not a numeric character." << endl;
}

isgraph

Testet, ob ein Element in einem Gebietsschema ein alphanumerisches Zeichen oder ein Interpunktionszeichen ist.

template <class CharType>
bool isgraph(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende Element enthält.

Rückgabewert

true wenn das getestete Element ein alphanumerisches oder interpunktionszeichen ist; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: graph, Ch).

Beispiel

// locale_is_graph.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isgraph ( 'L', loc );
   bool result2 = isgraph ( '\t', loc );
   bool result3 = isgraph ( '.', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is\n "
           << "an alphanumeric or punctuation character." << endl;
   else
      cout << "The character 'L' in the locale is\n "
           << " not an alphanumeric or punctuation character." << endl;

   if ( result2 )
      cout << "The character 'backslash-t' in the locale is\n "
           << "an alphanumeric or punctuation character." << endl;
   else
      cout << "The character 'backslash-t' in the locale is\n "
           << "not an alphanumeric or punctuation character." << endl;

   if ( result3 )
      cout << "The character '.' in the locale is\n "
           << "an alphanumeric or punctuation character." << endl;
   else
      cout << "The character '.' in the locale is\n "
           << " not an alphanumeric or punctuation character." << endl;
}

islower

Testet, ob ein Element in einem Gebietsschema kleingeschrieben ist.

template <class CharType>
bool islower(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende Element enthält.

Rückgabewert

true wenn das getestete Element ein Kleinbuchstaben ist; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: lower, Ch).

Beispiel

// locale_islower.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = islower ( 'L', loc );
   bool result2 = islower ( 'n', loc );
   bool result3 = islower ( '3', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a lowercase character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a lowercase character." << endl;

   if ( result2 )
      cout << "The character 'n' in the locale is "
           << "a lowercase character." << endl;
   else
      cout << "The character 'n' in the locale is "
           << " not a lowercase character." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "a lowercase character." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not a lowercase character." << endl;
}

isprint

Testet, ob ein Element in einem Gebietsschema ein druckbares Zeichen ist.

template <class CharType>
bool isprint(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende Element enthält.

Rückgabewert

true wenn das getestete Element druckbar ist; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: print, Ch).

Beispiel

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

int main( )
{
   locale loc ( "German_Germany" );

   bool result1 = isprint ( 'L', loc );
   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a printable character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a printable character." << endl;

   bool result2 = isprint( '\t', loc );
   if ( result2 )
      cout << "The character 'backslash-t' in the locale is "
           << "a printable character." << endl;
   else
      cout << "The character 'backslash-t' in the locale is "
           << " not a printable character." << endl;

   bool result3 = isprint( '\n', loc );
   if ( result3 )
      cout << "The character 'backslash-n' in the locale is "
           << "a printable character." << endl;
   else
      cout << "The character 'backslash-n' in the locale is "
           << " not a printable character." << endl;
}

ispunct

Testet, ob ein Element in einem Gebietsschema ein Interpunktionszeichen ist.

template <class CharType>
bool ispunct(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende Element enthält.

Rückgabewert

true wenn das getestete Element ein Interpunktionszeichen ist; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: punct, Ch).

Beispiel

// locale_ispunct.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = ispunct ( 'L', loc );
   bool result2 = ispunct ( ';', loc );
   bool result3 = ispunct ( '*', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a punctuation character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a punctuation character." << endl;

   if ( result2 )
      cout << "The character ';' in the locale is "
           << "a punctuation character." << endl;
   else
      cout << "The character ';' in the locale is "
           << " not a punctuation character." << endl;

   if ( result3 )
      cout << "The character '*' in the locale is "
           << "a punctuation character." << endl;
   else
      cout << "The character '*' in the locale is "
           << " not a punctuation character." << endl;
}

isspace

Testet, ob ein Element in einem Gebietsschema ein Leerzeichen ist.

template <class CharType>
bool isspace(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende Element enthält.

Rückgabewert

true wenn das getestete Element ein Leerzeichen ist; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: space, Ch).

Beispiel

// locale_isspace.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isspace ( 'L', loc );
   bool result2 = isspace ( '\n', loc );
   bool result3 = isspace ( ' ', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a whitespace character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a whitespace character." << endl;

   if ( result2 )
      cout << "The character 'backslash-n' in the locale is "
           << "a whitespace character." << endl;
   else
      cout << "The character 'backslash-n' in the locale is "
           << " not a whitespace character." << endl;

   if ( result3 )
      cout << "The character ' ' in the locale is "
           << "a whitespace character." << endl;
   else
      cout << "The character ' ' in the locale is "
           << " not a whitespace character." << endl;
}

isupper

Testet, ob ein Element in einem Gebietsschema groß geschrieben ist.

template <class CharType>
bool isupper(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende Element enthält.

Rückgabewert

true wenn das getestete Element ein Großbuchstaben ist; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: upper, Ch).

Beispiel

// locale_isupper.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isupper ( 'L', loc );
   bool result2 = isupper ( 'n', loc );
   bool result3 = isupper ( '3', loc );

   if ( result1 )
      cout << "The character 'L' in the locale is "
           << "a uppercase character." << endl;
   else
      cout << "The character 'L' in the locale is "
           << " not a uppercase character." << endl;

   if ( result2 )
      cout << "The character 'n' in the locale is "
           << "a uppercase character." << endl;
   else
      cout << "The character 'n' in the locale is "
           << " not a uppercase character." << endl;

   if ( result3 )
      cout << "The character '3' in the locale is "
           << "a uppercase character." << endl;
   else
      cout << "The character '3' in the locale is "
           << " not a uppercase character." << endl;
}

isxdigit

Testet, ob ein Element in einem Gebietsschema ein Zeichen ist, mit dem eine Hexadezimalzahl dargestellt wird.

template <class CharType>
bool isxdigit(CharType Ch, const locale& Loc)

Parameter

Ch
Das zu testende Element.

Loc
Das Gebietsschema, das das zu testende Element enthält.

Rückgabewert

true wenn das getestete Element ein Zeichen ist, das verwendet wird, um eine hexadezimale Zahl darzustellen; false wenn nicht.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc is( ctype<CharType>:: xdigit, Ch).

Hexadezimale Ziffern verwenden Basis 16 unter Verwendung der Zahlen 0 bis 9 sowie der Buchstaben A bis F (ohne Berücksichtigung der Groß-/Kleinschreibung) zur Darstellung von Zahlen, um die Dezimalzahlen 0 bis 15 darzustellen.

Beispiel

// locale_isxdigit.cpp
// compile with: /EHsc
#include <locale>
#include <iostream>

using namespace std;

int main( )
{
   locale loc ( "German_Germany" );
   bool result1 = isxdigit ( '5', loc );
   bool result2 = isxdigit ( 'd', loc );
   bool result3 = isxdigit ( 'q', loc );

   if ( result1 )
      cout << "The character '5' in the locale is "
           << "a hexidecimal digit-character." << endl;
   else
      cout << "The character '5' in the locale is "
           << " not a hexidecimal digit-character." << endl;

   if ( result2 )
      cout << "The character 'd' in the locale is "
           << "a hexidecimal digit-character." << endl;
   else
      cout << "The character 'd' in the locale is "
           << " not a hexidecimal digit-character." << endl;

   if ( result3 )
      cout << "The character 'q' in the locale is "
           << "a hexidecimal digit-character." << endl;
   else
      cout << "The character 'q' in the locale is "
           << " not a hexidecimal digit-character." << endl;
}

tolower

Konvertiert ein Zeichen in einen Kleinbuchstaben.

template <class CharType>
CharType tolower(CharType Ch, const locale& Loc)

Parameter

Ch
Das Zeichen, das in einen Kleinbuchstaben umgewandelt werden soll.

Loc
Das Gebietsschema, das das Zeichen enthält, welches konvertiert werden soll.

Rückgabewert

Das Zeichen, das in einen Kleinbuchstaben umgewandelt wird.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc tolower( Ch).

Beispiel

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

int main( )
{
   locale loc ( "German_Germany" );
   char result1 = tolower ( 'H', loc );
   cout << "The lower case of 'H' in the locale is: "
        << result1 << "." << endl;
   char result2 = tolower ( 'h', loc );
   cout << "The lower case of 'h' in the locale is: "
        << result2 << "." << endl;
   char result3 = tolower ( '$', loc );
   cout << "The lower case of '$' in the locale is: "
        << result3 << "." << endl;
}

toupper

Konvertiert ein Zeichen in einen Großbuchstaben.

template <class CharType>
CharType toupper(CharType Ch, const locale& Loc)

Parameter

Ch
Das Zeichen, das in einen Großbuchstaben umgewandelt werden soll.

Loc
Das Gebietsschema, das das Zeichen enthält, welches konvertiert werden soll.

Rückgabewert

Das Zeichen, das in einen Großbuchstaben konvertiert wurde.

Hinweise

Die Vorlagenfunktion gibt use_facet<ctype<CharType>>( ) zurück. Loc toupper( Ch).

Beispiel

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

int main( )
{
   locale loc ( "German_Germany" );
   char result1 = toupper ( 'h', loc );
   cout << "The upper case of 'h' in the locale is: "
        << result1 << "." << endl;
   char result2 = toupper ( 'H', loc );
   cout << "The upper case of 'H' in the locale is: "
        << result2 << "." << endl;
   char result3 = toupper ( '$', loc );
   cout << "The upper case of '$' in the locale is: "
        << result3 << "." << endl;
}

use_facet

Gibt einen Verweis auf ein Facet eines angegebenen Typs zurück, der in einem Gebietsschema gespeichert wird.

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

Parameter

Loc
Das const-Gebietsschema, das den Typ des Facets enthält, auf den verwiesen wird.

Rückgabewert

Ein Verweis auf das im Argumentgebietsschema enthaltene Facet der Klasse Facet.

Hinweise

Der Verweis auf das von der Vorlagenfunktion zurückgegebene Facet bleibt gültig, solange jede Kopie des enthaltenen Gebietsschemas vorhanden ist. Wenn kein solches Facetobjekt der Klasse Facet im Argument-Gebietsschema aufgeführt ist, löst die Funktion eine bad_cast-Ausnahme aus.

Beispiel

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

int main( )
{
   locale loc1 ( "German_Germany" ), loc2 ( "English_Australia" );
   bool result1 = use_facet<ctype<char> > ( loc1 ).is(
   ctype_base::alpha, 'a'
);
   bool result2 = use_facet<ctype<char> > ( loc2 ).is( ctype_base::alpha, '!'
   );

   if ( result1 )
      cout << "The character 'a' in locale loc1 is alphabetic."
           << endl;
   else
      cout << "The character 'a' in locale loc1 is not alphabetic."
           << endl;

   if ( result2 )
      cout << "The character '!' in locale loc2 is alphabetic."
           << endl;
   else
      cout << "The character '!' in locale loc2 is not alphabetic."
           << endl;
}
The character 'a' in locale loc1 is alphabetic.
The character '!' in locale loc2 is not alphabetic.

Siehe auch

<Gebietsschema>