std::wstring_convert::converted
De cppreference.com
|
|
Esta página se ha traducido por ordenador/computador/computadora de la versión en inglés de la Wiki usando Google Translate.
La traducción puede contener errores y palabras aparatosas/incorrectas. Planea sobre el texto para ver la versión original. Puedes ayudar a corregir los errores y mejorar la traducción. Para instrucciones haz clic aquí. |
| Definido en el archivo de encabezado <locale>
|
||
std::size_t converted() const;
|
||
Returns the number of source characters that were processed by the most recent from_bytes() or to_bytes().
Valor de retorno
The number of characters consumed by the most recent conversion operation.
Ejemplo
Ejecuta este código
#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
int main()
{
std::string utf8 = u8"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';
}
Salida:
original UTF-8 string size: 10
UTF-32 string size: 4
converted() == 10
new UTF-8 string size: 10
converted() == 4
Ver también
convierte una cadena de ancho en una cadena de bytes Original: converts a wide string into a byte string The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro pública) | |
convierte una cadena de bytes en una cadena de ancho Original: converts a byte string into a wide string The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función miembro pública) |