Sdílet prostřednictvím


<locale> – funkce

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

has_facet

Ověřuje, zda je v zadaném národním prostředí uložena konkrétní omezující vlastnost.

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

Parametry

Loc
Národní prostředí, které se má testovat na přítomnost omezující vlastnosti.

Návratová hodnota

true má-li národní prostředí testovanou omezující vlastnost; false pokud ne.

Poznámky

Funkce šablony je užitečná pro kontrolu, jestli jsou nespravované omezující vlastnosti uvedeny v národním prostředí dříve use_facet , aby se zabránilo výjimce, která by byla vyvolána, pokud by nebyla přítomna.

Příklad

// 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

Ověřuje, zda je prvek v národním prostředí abecední, nebo číselný znak.

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

Parametry

Ch
Alfanumerický prvek, který se má testovat.

Loc
Národní prostředí obsahující alfanumerický prvek, který se má testovat.

Návratová hodnota

true pokud je testovaný prvek alfanumerický; false pokud tomu tak není.

Příklad

// 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

Testuje, zda je prvek v národním prostředí abecední znak.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující abecední prvek, který se má testovat.

Návratová hodnota

true pokud je testovaný prvek abecední; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: alpha; Ch).

Příklad

// 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

Ověřuje, zda je prvek v národním prostředí řídicí znak.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující prvek, který se má testovat.

Návratová hodnota

true pokud testovaný prvek je řídicí znak; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: cntrl, Ch).

Příklad

// 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

Ověřuje, zda je prvek v národním prostředí číselný znak.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující prvek, který se má testovat.

Návratová hodnota

true je-li testovaný prvek číselným znakem; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: digit; Ch).

Příklad

// 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

Ověřuje, zda je prvek v národním prostředí alfanumerický znak nebo znak interpunkce.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující prvek, který se má testovat.

Návratová hodnota

true pokud je testovaný prvek alfanumerický nebo interpunkční znak; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: graph, Ch).

Příklad

// 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

Ověřuje, zda je prvek v národním prostředí malé písmeno.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující prvek, který se má testovat.

Návratová hodnota

true je-li testovaný prvek malými písmeny; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: lower, Ch).

Příklad

// 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

Ověřuje, zda je prvek v národním prostředí znak, který lze vytisknout.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující prvek, který se má testovat.

Návratová hodnota

true pokud je testovaný prvek tisknutelný; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: print, Ch).

Příklad

// 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

Ověřuje, zda je prvek v národním prostředí znak interpunkce.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující prvek, který se má testovat.

Návratová hodnota

true pokud testovaný prvek je interpunkční znak; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: punct, Ch).

Příklad

// 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

Ověřuje, zda je prvek v národním prostředí prázdný znak.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující prvek, který se má testovat.

Návratová hodnota

true pokud testovaný prvek je prázdný znak; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: space, Ch).

Příklad

// 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

Testuje, zda je prvek v národním prostředí velkými písmeny.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující prvek, který se má testovat.

Návratová hodnota

true je-li testovaný prvek velkými písmeny; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: upper; Ch).

Příklad

// 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

Ověřuje, zda je prvek v národním prostředí znak používaný ke znázornění šestnáctkového čísla.

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

Parametry

Ch
Prvek, který se má testovat.

Loc
Národní prostředí obsahující prvek, který se má testovat.

Návratová hodnota

true je-li testovaný prvek znakem, který představuje šestnáctkové číslo; false pokud tomu tak není.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc is( ctype<CharType>:: xdigit, Ch).

Šestnáctkové číslice používají základ 16 k reprezentaci čísel pomocí čísel 0 až 9 plus malá a malá písmena A až F, aby představovala desetinná čísla 0 až 15.

Příklad

// 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

Převede znak na malé písmeno.

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

Parametry

Ch
Znak, který se má převést na malá písmena.

Loc
Národní prostředí obsahující znak, který se má převést.

Návratová hodnota

Znak převedený na malá písmena.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc tolower( Ch).

Příklad

// 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

Převede znak na velké písmeno.

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

Parametry

Ch
Znak, který se má převést na velká písmena.

Loc
Národní prostředí obsahující znak, který se má převést.

Návratová hodnota

Znak se převede na velká písmena.

Poznámky

Funkce šablony vrátí use_facet<ctype<CharType>>( ). Loc toupper( Ch).

Příklad

// 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

Vrátí odkaz na omezující vlastnost určitého typu uloženou v národním prostředí.

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

Parametry

Loc
Národní prostředí const obsahující typ omezující vlastnosti, na kterou se odkazuje.

Návratová hodnota

Odkaz na omezující vlastnost třídy Facet obsaženou v národním prostředí argumentu.

Poznámky

Odkaz na omezující vlastnost vrácenou funkcí šablony zůstává platný, pokud existuje jakákoli kopie obsahujícího národního prostředí. Pokud není takový omezující objekt třídy Facet uveden v národním prostředí argumentu, funkce vyvolá bad_cast výjimku.

Příklad

// 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.

Viz také

<locale>