Espaços nominais
Variantes
Acções

std::mbsrtowcs

Da cppreference.com
< cpp‎ | string‎ | multibyte

 
 
Biblioteca cordas
Strings terminadas
Original:
Null-terminated strings
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cadeias de bytes
Multibyte cordas
Cordas de largura
Classes
Original:
Classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_string
char_traits
 
Strings terminadas multibyte
Wide / multibyte conversões
Original:
Wide/multibyte conversions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mbsinit
mbtowc
mbstowcs
btowc
mbrtowc
mbsrtowcs
mbrtoc16(C++11)
mbrtoc32(C++11)
mblen
Tipos
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
mbstate_t
 
Defined in header <cwchar>
std::size_t mbsrtowcs( wchar_t* dst,

                       const char** src,
                       std::size_t len,

                       std::mbstate_t* ps );
Converte uma terminação nula sequência de caracteres multibyte, que começa no estado de conversão descrito por *ps, a partir da matriz cujo primeiro elemento é apontado por *src à sua representação de caracteres de largura. Se dst não é nulo, os caracteres convertidos são armazenados nos elementos sucessivos da matriz wchar_t apontado por dst. Não mais do que len caracteres largos são escritos para a matriz destino.
Original:
Converts a null-terminated multibyte character sequence, which begins in the conversion state described by *ps, from the array whose first element is pointed to by *src to its wide character representation. If dst is not null, converted characters are stored in the successive elements of the wchar_t array pointed to by dst. No more than len wide characters are written to the destination array.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cada personagem multibyte é convertido como se por uma chamada para std::mbrtowc. A conversão pára se:
Original:
Each multibyte character is converted as if by a call to std::mbrtowc. The conversion stops if:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • O caractere nulo multibyte foi convertido e armazenado. src está definido para NULL e *ps representa o estado deslocamento inicial.
    Original:
    The multibyte null character was converted and stored. src is set to NULL and *ps represents the initial shift state.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Um personagem multibyte inválido (de acordo com o atual C locale) foi encontrado. src está definido para apontar para o início do primeiro caractere multibyte não convertido.
    Original:
    An invalid multibyte character (according to the current C locale) was encountered. src is set to point at the beginning of the first unconverted multibyte character.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • o próximo caractere de largura para ser armazenado exceder len. src é ajustado para apontar para o início do primeiro caractere multibyte não convertido. Esta condição não é verificado se dst==NULL.
    Original:
    the next wide character to be stored would exceed len. src is set to point at the beginning of the first unconverted multibyte character. This condition is not checked if dst==NULL.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

Índice

[editar] Parâmetros

dst -
ponteiro para matriz de caracteres de largura, onde os resultados serão armazenados
Original:
pointer to wide character array where the results will be stored
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
src -
ponteiro para ponteiro para o primeiro elemento de uma seqüência multibyte terminada em null
Original:
pointer to pointer to the first element of a null-terminated multibyte string
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
len -
número de caracteres largos disponíveis na matriz apontada por dst
Original:
number of wide characters available in the array pointed to by dst
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ps -
ponteiro para o objeto de estado de conversão
Original:
pointer to the conversion state object
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[editar] Valor de retorno

Em caso de sucesso, retorna o número de caracteres de largura, excluindo o L'\0' terminação, escrito para a matriz de caracteres.. Se dst==NULL, retorna o número de caracteres de largura que teria sido escrito dado comprimento ilimitado.
Original:
On success, returns the number of wide characters, excluding the terminating L'\0', written to the character array.. If dst==NULL, returns the number of wide characters that would have been written given unlimited length.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Em caso de erro de conversão (se caracteres multibyte inválido foi encontrado), retorna static_cast<std::size_t>(-1), lojas EILSEQ em errno e deixa *ps em estado indeterminado.
Original:
On conversion error (if invalid multibyte character was encountered), returns static_cast<std::size_t>(-1), stores EILSEQ in errno, and leaves *ps in unspecified state.
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 <vector>
#include <clocale>
#include <cwchar>
 
void print_as_wide(const char* mbstr)
{
    std::mbstate_t state = std::mbstate_t();
    int len = 1 + std::mbsrtowcs(NULL, &mbstr, 0, &state);
    std::vector<wchar_t> wstr(len);
    std::mbsrtowcs(&wstr[0], &mbstr, wstr.size(), &state);
    std::wcout << "Wide string: " << &wstr[0] << '\n'
               << "The length, including '\\0': " << wstr.size() << '\n';
}
 
int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    const char* mbstr = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋"
                        // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
    print_as_wide(mbstr);
}

Output:

Wide string: zß水𝄋
The length, including '\0': 5

[editar] Veja também

converte o caractere multibyte ao lado de caráter amplo, determinado estado
Original:
converts the next multibyte character to wide character, 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]
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 externT a Internt, como quando lendo de um arquivo
Original:
converts a string from externT to internT, such as when reading from 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]
C documentation for mbsrtowcs