C++ 本地化庫 - 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 − 它是成員型別 mask 的位掩碼。

  • c − 它是待分類的字元。

  • vec − 它是目標陣列。

返回值

如果 c 屬於作為 mask m 傳遞的任何類別,則返回 true。

異常

強保證 − 如果丟擲異常,則沒有任何影響。

資料競爭

訪問本地化物件。

示例

下面的例子解釋了 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.
locale.htm
廣告