C ++ wcslen () - Libreria standard C ++

La funzione wcslen () in C ++ restituisce la lunghezza della stringa ampia data.

La funzione wcslen () è definita nel file di intestazione.

prototipo di wcslen ()

 size_t wcslen (const wchar_t * str);

Wcslen () accetta come argomento una stringa ampia con terminazione null e ne restituisce la lunghezza. La lunghezza non include il carattere null wide. Se non è presente alcun carattere null nella stringa wide, il comportamento della funzione non è definito.

Parametri wcslen ()

  • str: puntatore alla stringa wide terminata da null la cui lunghezza deve essere calcolata.

wcslen () Restituisce il valore

  • La funzione wcslen () restituisce la lunghezza della stringa estesa terminata da null.

Esempio: come funziona la funzione wcslen ()?

 #include #include #include using namespace std; int main() ( setlocale(LC_ALL, "en_US.utf8"); wchar_t str1() = L"Hello Worldu0021"; wchar_t str2() = L"u0764u077au077cu079fu07a1u072e"; int len1 = wcslen(str1); int len2 = wcslen(str2); cout << "Length of str1 = " << len1 << endl; cout << "Length of str2 = " << len2 < len2) cout << "str1 is longer than str2"; else if (len1 < len2) cout << "str2 is longer than str1"; else cout << "str1 and str2 are of equal length"; return 0; )

Quando esegui il programma, l'output sarà:

 Lunghezza di str1 = 12 Lunghezza di str2 = 6 str1 è più lunga di str2

Articoli interessanti...