次の方法で共有


ctype::is

単一の文字が特定の属性を持ち、または範囲内の各文字の属性を並べ替え、配列に格納するかどうかをテストします。

bool is(
    mask maskVal, 
    CharType ch
) const;
const CharType *is(
    const CharType* first, 
    const CharType* last,
    mask* dest
) const;

パラメーター

  • maskVal
    文字がテストされる値のマスク。

  • ch
    属性をテストする文字。

  • first
    属性を並べ替えた範囲の最初の文字へのポインター。

  • last
    属性を並べ替えた範囲の最後の文字に続く文字へのポインター。

  • dest
    マスクが機能することを評価する配列の先頭へのポインターは、の各文字の属性格納する必要があります。

戻り値

一つ目のメンバー関数はテストされる文字にマスクの値で示す属性がある場合はを返します true ; 属性がない false。

2 番目のメンバー関数は、属性を並べ替えた範囲の最後の文字へのポインターを返します。

解説

マスクは ctype の派生クラスによって提供されます ctype_base のクラス文字の属性を並べ替えることを評価します。一つ目のメンバー関数はビットマスクと呼ばれると論理的なビットごとの作成、最初のパラメーターの式を使用できる演算子はマスクの値の組み合わせ (|、&、| ^)。

使用例

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

int main() {
   locale loc1 ( "German_Germany" ), loc2 ( "English_Australia" );

   if (use_facet<ctype<char> > ( loc1 ).is( ctype_base::alpha, 'a' ))
      cout << "The character 'a' in locale loc1 is alphabetic." 
           << endl;
   else
      cout << "The character 'a' in locale loc1 is not alphabetic." 
           << endl;

   if (use_facet<ctype<char> > ( loc2 ).is( ctype_base::alpha, '!' ))
      cout << "The character '!' in locale loc2 is alphabetic." 
           << endl;
   else
      cout << "The character '!' in locale loc2 is not alphabetic." 
           << endl;

   char *string = "Hello, my name is John!";
   ctype<char>::mask maskarray[30];
   use_facet<ctype<char> > ( loc2 ).is(
      string, string + strlen(string), maskarray );
   for (unsigned int i = 0; i < strlen(string); i++) {
      cout << string[i] << ": "
           << (maskarray[i] & ctype_base::alpha ? "alpha"
                                                : "not alpha")
           << endl;;
   };
}

出力

The character 'a' in locale loc1 is alphabetic.
The character '!' in locale loc2 is not alphabetic.
H: alpha
e: alpha
l: alpha
l: alpha
o: alpha
,: not alpha
 : not alpha
m: alpha
y: alpha
 : not alpha
n: alpha
a: alpha
m: alpha
e: alpha
 : not alpha
i: alpha
s: alpha
 : not alpha
J: alpha
o: alpha
h: alpha
n: alpha
!: not alpha

必要条件

ヘッダー: <locale>

名前空間: std

参照

関連項目

ctype Class