std::wcslen(3)
π std::wcslen(3) β C++ Standard Libary π
πΈ NAME πΈ
std::wcslen β std::wcslen. Literally the wide-string length girlie, and she's iconic for counting non-null wide chars before the terminating null wide character. No cap.
π¦ Synopsis π¦
Defined in header <cwchar> β write it down bestie.
std::size_t wcslen( const wchar_t* str );
Returns the length of a wide string, that is the number of non-null wide characters that precede the terminating null wide character.
π¨ Behavior check: the behavior is undefined if there is no null character in the wide character array pointed to by str. That's a hard no, fr fr.
π Parameters π
strβ pointer to the null-terminated wide string to be examined. Yes, she's the main character here.
β¨ Return value β¨
The length of the null-terminated wide string str. Periodt.
π§ Possible implementation π§
One possible implementation, looking cute:
std::size_t wcslen(const wchar_t* start)
{
// NB: start is not checked for nullptr!
const wchar_t* end = start;
while (*end != L'\0')
++end;
return end - start;
}
π Example π
// Run this code
#include <clocale>
#include <cwchar>
#include <iostream>
int main()
{
const wchar_t* str = L"ηγγγͺγ’γ«οΌεΌΎγγγ·γγγΉοΌγγγγ·γ₯γ‘γ³γγγ£γΉγγ―γΌγ«γοΌ";
std::setlocale(LC_ALL, "en_US.utf8");
std::wcout.imbue(std::locale("en_US.utf8"));
std::wcout << "The length of \"" << str << "\" is " << std::wcslen(str) << '\n';
}
π Output π
The length of "ηγγγͺγ’γ«οΌεΌΎγγγ·γγγΉοΌγγγγ·γ₯γ‘γ³γγγ£γΉγγ―γΌγ«γοΌ" is 32
Lowkey obsessed with that output. It ate.
π See also π
strlenβ returns the length of a given string (function)mblenβ returns the number of bytes in the next multibyte character (function)- C documentation for
wcslen
π«Ά source vibes:http://cppreference.comΒ· version/date:2024.06.10Β· bye bestie, go count those wide chars π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms