std::mbtowc
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 <cstdlib>
|
||
int mbtowc( wchar_t* pwc, const char* s, std::size_t n ) |
||
Convierte un carácter multibyte cuyo primer byte es apuntado por
s
a un carácter ancho, escrita a *pwc
pwc
si no es nulo .Original:
Converts a multibyte character whose first byte is pointed to by
s
to a wide character, written to *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.
You can help to correct and verify the translation. Click here for instructions.
Si
s
es un puntero nulo, se restablece el estado de conversión global y determina si las secuencias de desplazamiento se utilizan .Original:
If
s
is a null pointer, resets the global conversion state and determines whether shift sequences are used.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.
Contenido |
[editar] Parámetros
s | - | puntero al carácter multibyte
Original: pointer to the multibyte character 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. |
pwc | - | puntero al carácter ancho para la salida
Original: pointer to the wide character for output 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
Si
s
no es un puntero nulo, devuelve el número de bytes que se contienen en el carácter multibyte o -1 si los primeros bytes que apunta s
no forman un carácter multibyte válida o si 0 s
está apuntando a la charcter nulo '\0' .Original:
If
s
is not a null pointer, returns the number of bytes that are contained in the multibyte character or -1 if the first bytes pointed to by s
do not form a valid multibyte character or 0 if s
is pointing at the null charcter '\0'.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.
Si
s
es un puntero nulo, restablece su estado de conversión interna para representar el estado inicial de cambios y devoluciones si 0 la codificación multibyte actual no es dependiente del estado (no utiliza secuencias de turnos) o un valor distinto de cero si la codificación multibyte actual es dependiente del estado (utiliza secuencias de turnos) .Original:
If
s
is a null pointer, resets its internal conversion state to represent the initial shift state and returns 0 if the current multibyte encoding is not state-dependent (does not use shift sequences) or a non-zero value if the current multibyte encoding is state-dependent (uses shift sequences).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.
[editar] Notas
Cada llamada a las actualizaciones de estado interno
mbtowc
la conversión global (un objeto estático de std::mbstate_t tipo, sólo se sabe que esta función). Si la codificación multibyte utiliza estados de cambio, se debe tener cuidado para evitar las exploraciones de rastreo o múltiples. En cualquier caso, varios subprocesos no debe llamar mbtowc
sin sincronización: std::mbrtowc lugar se puede utilizar .Original:
Each call to
mbtowc
updates the internal global conversion state (a static object of type std::mbstate_t, only known to this function). If the multibyte encoding uses shift states, care must be taken to avoid backtracking or multiple scans. In any case, multiple threads should not call mbtowc
without synchronization: std::mbrtowc may be used instead.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.
[editar] Ejemplo
Ejecuta este código
#include <iostream> #include <clocale> #include <cstring> #include <cstdlib> int print_mb(const char* ptr) { std::mbtowc(NULL, 0, 0); // reset the conversion state const char* end = ptr + std::strlen(ptr); int ret; for (wchar_t wc; (ret = std::mbtowc(&wc, ptr, end-ptr)) > 0; ptr+=ret) { std::wcout << wc; } std::wcout << '\n'; return ret; } 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:
zß水𝄋
[editar] Ver también
convierte el carácter multibyte junto al carácter amplio, estado dado 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. (función) | |
Devuelve el número de bytes en el carácter multibyte siguiente. (función) | |
[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 )
|
Documentación de C para mbtowc
|