C++ Locale 库 - is
描述
它是一个分类字符。
声明
以下是 std::ctype::is 的声明。
C++98
bool is (mask m, char_type c) const;
const char_type* is (const char_type* low,
const char_type* high, mask* vec) const;
C++11
bool is (mask m, char_type c) const;
const char_type* is (const char_type* low,
const char_type* high, mask* vec) const;
参数
m − 它是成员类型掩码的位掩码。
c − 它是一个可以分类的字符。
vec − 它是一个目标数组。
返回值
如果 c 归入作为掩码 m 传递的任何类别,则返回 true。
异常
Strong guarantee − 如果抛出异常,则没有任何影响。
数据竞争
访问了 locale 对象。
示例
在下面的例子中解释了 std::ctype::is。
#include <iostream>
#include <locale>
int main () {
std::locale loc;
const char quote[] = "Tutorialspoint is a one of the best site .";
std::cout << '"' << quote << "\"\n";
std::cout << "The quote begins with an uppercase letter? ";
std::cout << std::boolalpha;
std::cout << std::use_facet< std::ctype<char> >(loc).is (std::ctype
<char>::upper, quote[0]);
std::cout << '\n';
int cx = 0;
std::ctype<char>::mask * masks = new std::ctype<char>::mask [60];
std::use_facet< std::ctype<char> >(loc).is (quote, quote+60, masks);
for (int i=0; i<60; ++i) if (masks[i] & std::ctype<char>::space) ++cx;
std::cout << "The quote has " << cx << " whitespaces.\n";
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
"Tutorialspoint is a one of the best site ." The quote begins with an uppercase letter? true The quote has 8 whitespaces.

