<locale> 関数

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

has_facet

特定のファセットが指定されたロケールに格納されているかどうかをテストします。

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

パラメーター

Loc
ファセットの有無をテストするロケール。

戻り値

ロケールにテスト対象のファセットがある場合は true、ない場合は false

解説

このテンプレート関数は、use_facet を呼び出す前に必須ではないファセットがロケール内にリストされているかどうかを確認し、なかった場合に例外がスローされるのを回避するために役立ちます。

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

ロケールの要素が英字または数字であるかどうかをテストします。

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

パラメーター

Ch
テストする英数字要素。

Loc
テストする英数字要素を含むロケール。

戻り値

テストされた要素が英数字である場合は true、そうでない場合は false

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

ロケールの要素が英字であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする英字要素を含むロケール。

戻り値

テストされた要素が英字である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: alpha, Ch).

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

ロケールの要素が制御文字であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする要素を含むロケール。

戻り値

テストされた要素が制御文字である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: cntrl, Ch).

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

ロケールの要素が数字であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする要素を含むロケール。

戻り値

テストされた要素が数字である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: digit, Ch).

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

ロケールの要素が英字または句読点であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする要素を含むロケール。

戻り値

テストされた要素が英字または句読点である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: graph, Ch).

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

ロケールの要素が小文字であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする要素を含むロケール。

戻り値

テストされた要素が小文字である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: lower, Ch)。

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

ロケールの要素が印刷可能な文字であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする要素を含むロケール。

戻り値

テストされた要素が印刷可能である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: print, Ch).

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

ロケールの要素が句読点であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする要素を含むロケール。

戻り値

テストされた要素が句読点である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: punct, Ch).

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

ロケールの要素が空白文字であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする要素を含むロケール。

戻り値

テストされた要素が空白文字である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: space, Ch).

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

ロケールの要素が大文字であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする要素を含むロケール。

戻り値

テストされた要素が大文字である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: upper, Ch)。

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

ロケールの要素が 16 進数を表すために使用される文字であるかどうかをテストします。

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

パラメーター

Ch
テストする要素。

Loc
テストする要素を含むロケール。

戻り値

テストする要素が 16 進数を表すために使用される文字である場合は true、そうでない場合は false

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). is( ctype<CharType>:: xdigit, Ch).

16 進数字は、0 から 9 までの数字と A から F までの文字 (大文字と小文字を区別しない) を使用して 0 から 15 までの 10 進数字を表す 16 進数を使用します。

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

文字を小文字に変換します。

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

パラメーター

Ch
小文字に変換される文字。

Loc
変換される文字を含むロケール。

戻り値

小文字に変換された文字。

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). tolower( Ch).

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

文字を大文字に変換します。

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

パラメーター

Ch
大文字に変換される文字。

Loc
変換される文字を含むロケール。

戻り値

大文字に変換された文字。

解説

このテンプレート関数は次を返します: use_facet<ctype<CharType>>( Loc). toupper( Ch).

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

ロケールに格納されている指定された型のファセットへの参照を返します。

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

パラメーター

Loc
参照されるファセットの型を含む const ロケール。

戻り値

引数のロケールに含まれるクラス Facet のファセットへの参照。

解説

このテンプレート関数によって返されるファセットへの参照は、含んでいるロケールのコピーが存在する限り有効です。 このようなクラス Facet のファセット オブジェクトが引数のロケールにリストされていない場合、この関数は bad_cast 例外をスローします。

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

関連項目

<ロケール>