C++ 中的wctype() 函數返回用於寬字符分類的 wctype_t 類型的值。
wctype() 函數在<cwctype> 頭文件中定義。
wctype()原型
wctype_t wctype(const char* str);
wctype() 函數將 C 字符串 str
作為其參數,並返回用於對寬字符進行分類的 wctype_t 類型的值。
參數:
str
:指定所需類別的 C 字符串。
str 的值 | 等效函數 |
---|---|
alnum | iswalnum |
alpha | iswalpha |
blank | iswblank |
cntrl | iswcntrl |
digit | iswdigit |
graph | iswgraph |
lower | iswlower |
iswprint | |
punct | iswpunct |
space | iswspace |
xdigit | iswxdigit |
upper | iswupper |
返回:
- wctype() 函數返回一個 wctype_t 對象,該對象可與 towctype() 一起使用以檢查寬字符的屬性。
- 如果 str 不提供當前 C 語言環境支持的類別,則返回零。
示例:wctype() 函數如何工作?
#include <cwctype>
#include <iostream>
#include <clocale>
using namespace std;
int main()
{
setlocale(LC_ALL, "en_US.UTF-8");
wchar_t wc = L'\u00b5';
if (iswctype(wc, wctype("digit")))
wcout << wc << L" is a digit";
else if (iswctype(wc, wctype("alpha")))
wcout << wc << L" is an alphabet";
else
wcout << wc << L" is neither an alphabet nor a digit";
return 0;
}
運行程序時,輸出將是:
µ is an alphabet
相關用法
- C++ wctype()用法及代碼示例
- C++ wctrans()用法及代碼示例
- C++ wctob()用法及代碼示例
- C++ wctomb()用法及代碼示例
- C++ wcstold()用法及代碼示例
- C++ wcerr用法及代碼示例
- C++ wcsftime()用法及代碼示例
- C++ wcstod()用法及代碼示例
- C++ wcscspn()用法及代碼示例
- C++ wcsncmp()用法及代碼示例
- C++ wcin用法及代碼示例
- C++ wcstok()用法及代碼示例
- C++ wcsstr()用法及代碼示例
- C++ wcsrchr()用法及代碼示例
- C++ wcsncpy()用法及代碼示例
- C++ wcslen()用法及代碼示例
- C++ wcsspn()用法及代碼示例
- C++ wclog用法及代碼示例
- C++ wcschr()用法及代碼示例
- C++ wcstof()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ wctype()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。