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,则无法具有特性。

第二个成员函数返回指向在属性中的分类范围的最后一个字符。

备注

值类别字符的属性选件类提供掩码 ctype_base选件类,ctype派生。 第一个成员函数可以接受从掩码值的组合称为位掩码和按位窗体的第一个参数的表达式按逻辑运算符(|,&,^,|)。

示例

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

Output

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