Espacios de nombres
Variantes
Acciones

std::mbrtowc

De cppreference.com
< cpp‎ | string‎ | multibyte
 
 
 
Cadenas multibyte terminadas en nulo
Ancho / multibyte conversiones
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.
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.
 
Definido en el archivo de encabezado <cwchar>
std::size_t mbrtowc( wchar_t* pwc,

                     const char* s,
                     std::size_t n,

                     std::mbstate_t* ps );
Convierte un carácter multibyte angosto a un carácter ancho .
Original:
Converts a narrow multibyte character to a wide character.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si s no es un puntero nulo, inspecciona en la mayoría de los bytes n de la cadena de caracteres de varios bytes, comenzando con el byte apuntado por s para determinar el número de bytes necesarios para completar el siguiente carácter multibyte (incluyendo cualquiera de las secuencias de desplazamiento). Si la función determina que el siguiente carácter multibyte en s es completa y válida, convierte al carácter ancho correspondiente y lo almacena en *pwc (si pwc no es nulo) .
Original:
If s is not a null pointer, inspects at most n bytes of the multibyte character string, beginning with the byte pointed to by s to determine the number of bytes necessary to complete the next multibyte character (including any shift sequences). If the function determines that the next multibyte character in s is complete and valid, converts it to the corresponding wide character and stores it in *pwc (if pwc is not null).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si s es un puntero nulo, los valores de n y pwc son ignorados y la llamada es equivalente a std::mbrtowc(NULL, "", 1, ps) .
Original:
If s is a null pointer, the values of n and pwc are ignored and call is equivalent to std::mbrtowc(NULL, "", 1, ps).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si el carácter amplio producido es el carácter nulo, el estado de conversión almacenados en *ps es el estado inicial de cambios .
Original:
If the wide character produced is the null character, the conversion state stored in *ps is 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.

Contenido

[editar] Parámetros

pwc -
puntero a la ubicación donde se realizará el carácter ancho resultante escrito
Original:
pointer to the location where the resulting wide character will be written
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
s -
puntero a la cadena de caracteres multibyte utiliza como entrada
Original:
pointer to the multibyte character string used as input
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
n -
limitar el número de bytes en s que puede ser examinado
Original:
limit on the number of bytes in s that can be examined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ps -
puntero al estado de conversión utilizado en la interpretación de la cadena multibyte
Original:
pointer to the conversion state used when interpreting the multibyte string
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

El primero de los siguientes que corresponda:
Original:
The first of the following that applies:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
  • 0 Si el carácter de s (y se almacena en pwc si no nulo) fue el carácter nulo
    Original:
    0 if the character converted from s (and stored in pwc if non-null) was the null character
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • el número de bytes de [1...n] el carácter multibyte convertidos con éxito desde s
    Original:
    the number of bytes [1...n] of the multibyte character successfully converted from s
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • static_cast<std::size_t>(-2) si los bytes n próximos constituir un incompleto, pero hasta ahora vigente, el carácter multibyte. Nada está escrito a *pwc .
    Original:
    static_cast<std::size_t>(-2) if the next n bytes constitute an incomplete, but so far valid, multibyte character. Nothing is written to *pwc.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • static_cast<std::size_t>(-1) si se produce error de codificación. No se escribe nada *pwc, la EILSEQ valor se almacena en errno y el valor de *ps se deja sin especificar .
    Original:
    static_cast<std::size_t>(-1) if encoding error occurs. Nothing is written to *pwc, the value EILSEQ is stored in errno and the value of *ps is left unspecified.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[editar] Ejemplo

#include <iostream>
#include <clocale>
#include <cstring>
#include <cwchar>
 
void print_mb(const char* ptr)
{
    std::mbstate_t state = std::mbstate_t(); // initial state
    const char* end = ptr + std::strlen(ptr);
    int len;
    wchar_t wc;
    while((len = std::mbrtowc(&wc, ptr, end-ptr, &state)) > 0) {
        std::wcout << "Next " << len << " bytes are the character " << wc << '\n';
        ptr += len;
    }
}
 
int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    const char* str = u8"z\u00df\u6c34\U0001d10b"; // or u8"zß水𝄋"
                      // or "\x7a\xc3\x9f\xe6\xb0\xb4\xf0\x9d\x84\x8b";
    print_mb(str);
}

Salida:

Next 1 bytes are the character z
Next 2 bytes are the character ß
Next 3 bytes are the character 水
Next 4 bytes are the character 𝄋

[editar] Ver también

Convierte el carácter multibyte siguiente a un carácter ancho.
(función) [editar]
convierte una carácter ancho a su representación multibyte, estado dado
Original:
converts a wide character to its multibyte representation, 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) [editar]
[virtual]
convierte una cadena de externT a internt, como cuando al leer el archivo
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.

(función miembro virtual protegida de std::codecvt) [editar]
Documentación de C para mbrtowc