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 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;;
};
}
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
要求
页眉: <区域设置>
命名空间: std