Espaços nominais
Variantes
Acções

std::wstring_convert::to_bytes

Da cppreference.com

 
 
Biblioteca localizações
Localidades e facetas
Original:
Locales and facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
locale
Classificação de caracteres
Original:
Character classification
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Conversões
Original:
Conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Facet classes base da categoria
Original:
Facet category base classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Categorias faceta
Original:
Facet categories
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Específicos da localidade facetas
Original:
Locale-specific facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Facetas de conversão de código
Original:
Code conversion facets
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
codecvt_utf8(C++11)
codecvt_utf16(C++11)
C localidade
Original:
C locale
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
std::wstring_convert
Funções de membro
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
wstring_convert::wstring_convert
wstring_convert::~wstring_convert
wstring_convert::from_bytes
wstring_convert::to_bytes
wstring_convert::converted
wstring_convert::state
 
Defined in header <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)
Executa larga para multibyte conversão, usando a faceta codecvt fornecidos em construção.
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.
1)
Converte wchar como se fosse uma corda de 1 comprimento, para byte_string
Original:
Converts wchar as if it was a string of length 1, 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.
2)
Converte terminada em nulo início seqüência de caracteres largos para o caráter amplo apontado por wptr, para byte_string
Original:
Converts the null-terminated wide character sequence beginning at the wide character pointed to by wptr, 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.
3)
Converte o str corda larga 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.
4)
Converte a seqüência de caracteres largos [first, last) para byte_string
Original:
Converts the wide character sequence [first, last) 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.
Em todos os casos, a conversão começa no estado de deslocamento inicial, a menos que não inicial estado de partida, foi fornecida a este construtor wstring_convert. O número de caracteres convertidos eo valor final do estado de conversão são lembrados e pode ser acessado com state() e 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.

Índice

[editar] Valor de retorno

Um objeto byte_string contendo os resultados da gama de multibyte conversão. Se a conversão falhou e houve um fornecida pelo usuário byte string de erro fornecido para o construtor desta wstring_convert, retorna esta cadeia de bytes de erros.
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.

[editar] Exceções

Se este objeto wstring_convert foi construído sem fornecido pelo usuário seqüência de bytes de erros, joga std::range_error em caso de falha de conversão.
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.

[editar] Exemplo

#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);
}

Output:

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

[editar] Veja também

converte uma seqüência de bytes em uma seqüência de largura
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.

(função pública membro) [edit]
converte uma cadeia ampla de cadeia de caracteres multibyte estreita, dado estado
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.

(função) [edit]
[virtual]
Converte uma cadeia de internt para externT, como ao escrever para o arquivo
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.

(virtual protegido of std::codecvt função de membro) [edit]