std::wstring_convert::to_bytes
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>
|
||
byte_string to_bytes( Elem wchar );
|
(1) | |
byte_string to_bytes( const Elem* wptr );
|
(2) | |
byte_string to_bytes( const wide_string& wstr );
|
(3) | |
byte_string to_bytes( const Elem* first, const Elem* last);
|
(4) | |
Realiza la conversión de ancho a multibyte, utilizando la faceta
codecvt suministrada en construcción .Original:
Performs wide to multibyte conversion, using the
codecvt facet supplied at construction.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
1)
Convierte
wchar como si fuera una cadena de longitud 1, a byte_stringOriginal:
Converts
wchar as if it was a string of length 1, to byte_stringThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
Convierte la terminación nula comienzo de ancho en la secuencia de caracteres de caracteres anchos apuntada por
wptr, a byte_stringOriginal:
Converts the null-terminated wide character sequence beginning at the wide character pointed to by
wptr, to byte_stringThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
3)
Convierte la cadena
str ancha para byte_string .Original:
Converts the wide string
str to byte_string.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
4)
Convierte el
[first, last) secuencia de caracteres de ancho a byte_stringOriginal:
Converts the wide character sequence
[first, last) to byte_stringThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
En todos los casos, la conversión comienza en el estado inicial de cambios, a menos que no inicial estado de partida se proporcionó a este constructor
wstring_convert. El número de caracteres convertidos y el valor final del estado de conversión se recuerdan y se puede acceder con state() y converted()Original:
In all cases, the conversion begins in initial shift state, unless non-initial starting state was provided to this
wstring_convert constructor. The number of characters converted and the final value of the conversion state are remembered and can be accessed with state() and converted()The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Valor de retorno
Un objeto
byte_string que contiene los resultados de la conversión de ancho a multibyte. Si la conversión no y no había suministrado por el usuario de byte error cadena proporcionada al constructor de esta wstring_convert, devuelve esa cadena de bytes de error .Original:
A
byte_string object containing the results of the wide to multibyte conversion. If the conversion failed and there was a user-supplied byte-error string provided to the constructor of this wstring_convert, returns that byte-error string.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Excepciones
Si este objeto
wstring_convert se construyó sin un usuario suministrado por byte de error de cadena, tira std::range_error en caso de fallo de conversión .Original:
If this
wstring_convert object was constructed without a user-supplied byte-error string, throws std::range_error on conversion failure.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ejemplo
Ejecuta este código
#include <iostream>
#include <string>
#include <locale>
#include <codecvt>
#include <iomanip>
// utility function for output
void hex_print(const std::string& s)
{
std::cout << std::hex << std::setfill('0');
for(unsigned char c : s)
std::cout << std::setw(2) << static_cast<int>(c) << ' ';
std::cout << std::dec << '\n';
}
int main()
{
// wide character data
std::wstring wstr = L"z\u00df\u6c34\U0001d10b"; // or L"zß水𝄋"
// wide to UTF-8
std::wstring_convert<std::codecvt_utf8<wchar_t>> conv1;
std::string u8str = conv1.to_bytes(wstr);
std::cout << "UTF-8 conversion produced " << u8str.size() << " bytes:\n";
hex_print(u8str);
// wide to UTF-16le
std::wstring_convert<std::codecvt_utf16<wchar_t, 0x10ffff, std::little_endian>> conv2;
std::string u16str = conv2.to_bytes(wstr);
std::cout << "UTF-16le conversion produced " << u16str.size() << " bytes:\n";
hex_print(u16str);
}
Salida:
UTF-8 conversion produced 10 bytes:
7a c3 9f e6 b0 b4 f0 9d 84 8b
UTF-16le conversion produced 10 bytes:
7a 00 df 00 34 6c 34 d8 0b dd
Ver también
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) | |
convierte una cadena a cadena estrecha gama de caracteres multibyte, estado dado Original: converts a wide string to narrow multibyte character string, given state The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (función) | |
[virtual] |
convierte una cadena de internt a externT, tales como cuando se escribe en el archivo Original: converts a string from internT to externT, such as when writing to file 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 virtual protegida de std::codecvt)
|