std::wstrin...t::converted(3)
πΈ NAME πΈ
okay so bestie, this page is std::wstring_convert::converted β and yes, the NAME line is literally std::wstring_convert::converted - std::wstring_convert::converted, because sometimes the manual just repeats itself and we respect it π
. Itβs from the C++ Standard Libary manual (spelling exactly as the page has it, no cap), and the page title is std::wstrin...t::converted(3).
β¨ Synopsis β¨
Defined in header <locale>:
std::size_t converted() const noexcept;
So this is the little member function that returns the number of source characters that were processed by the most recent from_bytes() or to_bytes() β lowkey the receipts for your last conversion, fr fr.
π Return value π
It returns the number of characters consumed by the most recent conversion operation. Thatβs the whole vibe: last conversion in, character count out β¨.
π§ Example π§
The page says // Run this code, and then gives you this absolute icon of a snippet:
#include <codecvt>
#include <iostream>
#include <locale>
#include <string>
int main()
{
std::string utf8 = "z\u00df\u6c34\U0001d10b"; // or u8"zΓζ°΄π"
// or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
std::cout << "original UTF-8 string size: " << utf8.size() << '\n';
// the UTF-8 - UTF-32 standard conversion facet
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> cvt;
// UTF-8 to UTF-32
std::u32string utf32 = cvt.from_bytes(utf8);
std::cout << "UTF-32 string size: " << utf32.size() << '\n';
std::cout << "converted() == " << cvt.converted() << '\n';
// UTF-32 to UTF-8
utf8 = cvt.to_bytes(utf32);
std::cout << "new UTF-8 string size: " << utf8.size() << '\n';
std::cout << "converted() == " << cvt.converted() << '\n';
}
π Output π
original UTF-8 string size: 10
UTF-32 string size: 4
converted() == 10
new UTF-8 string size: 10
converted() == 4
Not the output serving looks, bestie π β the counts are just doing their little conversion thing and we love that for them π«Ά.
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards. This is the βfix it in postβ section, and yes it still counts:
- DR:
LWG 2174 - Applied to:
C++11 - Behavior as published:
wstring_convert::convertedwas not required to benoexcept - Correct behavior:
required
π¦ See also π¦
to_bytesβ converts a wide string into a byte string (public member function)from_bytesβ converts a byte string into a wide string (public member function)
Thatβs the whole page, bestie! Source: http://cppreference.com; version/date: 2024.06.10; page: std::wstrin...t::converted(3). xoxo, go convert something cute ππ
π¦ 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