std::btowc(3)
β¨ NAME β¨
std::btowc - std::btowc.
Okay bestie, this is std::btowc(3) from the C++ Standard Libary manual β yes, the header spells it βLibary,β and we are absolutely not fixing the lore π
.
π Synopsis π
Defined in header <cwchar>:
std::wint_t btowc( int c );
So here's the vibe: it widens a single-byte character c to its wide character equivalent.
Most multibyte character encodings use single-byte codes to represent the characters from the ASCII character set. This function may be used to convert such characters to wchar_t.
π Parameters π
cβ single-byte character to widen.
π₯ Return value π₯
WEOF if c is EOF.
Wide character representation of c if (unsigned char)c is a valid single-byte character in the initial shift state, WEOF otherwise.
πΈ Example πΈ
The example literally says // Run this code, so obviously we run it. Here's the full code with all its details intact:
#include <clocale>
#include <cwchar>
#include <iostream>
void try_widen(char c)
{
std::wint_t w = std::btowc(c);
if (w != WEOF)
std::cout << "The single-byte character " << +(unsigned char)c
<< " widens to " << +w << '\n';
else
std::cout << "The single-byte character " << +(unsigned char)c
<< " failed to widen\n";
}
int main()
{
std::setlocale(LC_ALL, "lt_LT.iso88594");
std::cout << std::hex << std::showbase << "In Lithuanian ISO-8859-4 locale:\n";
try_widen('A');
try_widen('\xdf'); // German letter Γ (U+00df) in ISO-8859-4
try_widen('\xf9'); // Lithuanian letter Ε³ (U+0173) in ISO-8859-4
std::setlocale(LC_ALL, "lt_LT.utf8");
std::cout << "In Lithuanian UTF-8 locale:\n";
try_widen('A');
try_widen('\xdf');
try_widen('\xf9');
}
β¨ Possible output β¨
In Lithuanian ISO-8859-4 locale:
The single-byte character 0x41 widens to 0x41
The single-byte character 0xdf widens to 0xdf
The single-byte character 0xf9 widens to 0x173
In Lithuanian UTF-8 locale:
The single-byte character 0x41 widens to 0x41
The single-byte character 0xdf failed to widen
The single-byte character 0xf9 failed to widen
π See also π
wctobβ narrows a wide character to a single-byte narrow character, if possible (function)do_widenβ converts a character or characters fromchartoCharT[virtual](virtual protected member function ofstd::ctype<CharT>)- C documentation for
btowc
Source/version/date sign-off, because the footer said so: http://cppreference.com, 2024.06.10, std::btowc(3). Bye bestie, go widen something iconic π«Άβ¨
π¦ 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