std::wctob(3)
β¨ NAME β¨
okay so bestie, this is std::wctob from the C++ Standard Libary (section 3) β yes, the header really spells it like that, no cap π. The NAME line is literally std::wctob - std::wctob, and honestly? iconic.
π¦ SYNOPSIS π¦
Defined in header <cwchar>
int wctob( std::wint_t c );
It narrows a wide character c if its multibyte character equivalent in the initial shift state is a single byte. This is typically possible for the characters from the ASCII character set, since most multibyte encodings (such as UTF-8) use single bytes to encode those characters. slay π
π PARAMETERS π
cβ wide character to narrow π«Ά
π₯ RETURN VALUE π₯
EOF if c does not represent a multibyte character with length 1 in initial shift state. periodt.
Otherwise, the single-byte representation of c as unsigned char converted to int. cute.
π EXAMPLE π
// Run this code
#include <clocale>
#include <cwchar>
#include <iostream>
void try_narrowing(wchar_t c)
{
int cn = std::wctob(c);
if (cn != EOF)
std::cout << '\'' << int(c) << "' narrowed to " << +cn << '\n';
else
std::cout << '\'' << int(c) << "' could not be narrowed\n";
}
int main()
{
std::setlocale(LC_ALL, "th_TH.utf8");
std::cout << std::hex << std::showbase << "In Thai UTF-8 locale:\n";
try_narrowing(L'a');
try_narrowing(L'ΰΉ');
std::setlocale(LC_ALL, "th_TH.tis620");
std::cout << "In Thai TIS-620 locale:\n";
try_narrowing(L'a');
try_narrowing(L'ΰΉ');
}
β OUTPUT β
In Thai UTF-8 locale:
'0x61' narrowed to 0x61
'0xe5b' could not be narrowed
In Thai TIS-620 locale:
'0x61' narrowed to 0x61
'0xe5b' narrowed to 0xfb
π SEE ALSO π
btowcβ widens a single-byte narrow character to wide character, if possible (function)narrowβ narrows characters (public member function ofstd::basic_ios<CharT,Traits>)narrowβ invokesdo_narrow(public member function ofstd::ctype<CharT>)- C documentation for
wctobβ C documentation forwctob
mwah π source/version/date vibes: http://cppreference.com, 2024.06.10, std::wctob(3). bye bestie π«Ά
π¦ 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