Funkce wcslen () v C ++ vrací délku daného širokého řetězce.
Funkce wcslen () je definována v hlavičkovém souboru.
prototyp wcslen ()
size_t wcslen (const wchar_t * str);
Wcslen () vezme jako argument argument null zakončený široký řetězec str a vrátí jeho délku. Délka nezahrnuje null široký znak. Pokud v širokém řetězci není žádný null široký znak, chování funkce není definováno.
Parametry wcslen ()
- str: Ukazatel na null ukončený široký řetězec, jehož délka se má vypočítat.
wcslen () Vrátit hodnotu
- Funkce wcslen () vrací délku širokého řetězce zakončeného hodnotou null.
Příklad: Jak funguje funkce 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; )
Když spustíte program, výstup bude:
Délka str1 = 12 Délka str2 = 6 str1 je delší než str2