La funzione wctype () in C ++ restituisce un valore di tipo wctype_t utilizzato per la classificazione dei caratteri estesi.
La funzione wctype () è definita nel file di intestazione.
prototipo di wctype ()
wctype_t wctype (const char * str);
La funzione wctype () accetta una stringa C str come argomento e restituisce un valore di tipo wctype_t che viene utilizzato per classificare un carattere ampio.
Parametri wctype ()
- str: stringa C che specifica la categoria desiderata.
Valore di str | Funzione equivalente |
---|---|
alnum | iswalnum |
alfa | iswalpha |
vuoto | iswblank |
cntrl | iswcntrl |
cifra | iswdigit |
grafico | iswgraph |
inferiore | iswlower |
Stampa | iswprint |
punct | iswpunct |
spazio | iswspace |
xdigit | iswxdigit |
superiore | iswupper |
wctype () Restituisce il valore
- La funzione wctype () restituisce un oggetto wctype_t che può essere utilizzato con towctype () per controllare la proprietà di un carattere ampio.
- Se str non fornisce una categoria supportata dalla locale C corrente, restituisce zero.
Esempio: come funziona la funzione wctype ()?
#include #include #include 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; )
Quando esegui il programma, l'output sarà:
µ è un alfabeto