Espacios de nombres
Variantes
Acciones

std::wcsrtombs

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.
wcsrtombs
(C++11)
(C++11)
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 wcsrtombs( char* dst,

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

                       std::mbstate_t* ps );
Convierte una secuencia de caracteres anchos del array cuyo primer elemento es apuntado por *src a su representación multibyte estrecho que comienza en el estado de conversión descrito por *ps. Si dst no es nulo, los caracteres convertidos se almacenan en los elementos sucesivos de la matriz de caracteres apuntada por dst. No más de len bytes se escriben en la matriz de destino .
Original:
Converts a sequence of wide characters from the array whose first element is pointed to by *src to its narrow multibyte representation that begins in the conversion state described by *ps. If dst is not null, converted characters are stored in the successive elements of the char array pointed to by dst. No more than len bytes 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 personaje se convierte como si de una llamada a std::wcrtomb. La conversión se para si:
Original:
Each character is converted as if by a call to std::wcrtomb. 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.
  • El carácter nulo se convierte y se almacena. src se establece NULL y *ps representa el estado inicial de cambios .
    Original:
    The 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.
  • Un wchar_t se encontró que no corresponde a un carácter válido en la actual configuración regional C. src se establece en el punto en el primer carácter ancho no convertido .
    Original:
    A wchar_t was found that does not correspond to a valid character in the current C locale. src is set to point at the first unconverted wide character.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • el carácter multibyte próximo a almacenar len se superan. src se establece en el punto en el primer carácter ancho no convertido. Esta condición no se comprueba si dst==NULL .
    Original:
    the next multibyte character to be stored would exceed len. src is set to point at the first unconverted wide 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.

Contenido

[editar] Parámetros

dst -
puntero al array de caracteres estrecha, donde los caracteres de varios bytes se almacenará
Original:
pointer to narrow character array where the multibyte characters 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 -
puntero a puntero al primer elemento de una cadena terminada en nulo de ancho
Original:
pointer to pointer to the first element of a null-terminated wide 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 bytes disponibles en el array apuntado por dst
Original:
number of bytes 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 -
puntero al objeto de estado de la conversión
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

En caso de éxito, devuelve el número de bytes (incluyendo cualquier secuencia de turnos, pero excluyendo el '\0' terminación) por escrito a la matriz de caracteres cuyo primer elemento es apuntado por dst. Si dst==NULL, devuelve el número de bytes que se han escrito .
Original:
On success, returns the number of bytes (including any shift sequences, but excluding the terminating '\0') written to the character array whose first element is pointed to by dst. If dst==NULL, returns the number of bytes that would have been written.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
En caso de error de conversión (si inválido carácter ancho fue encontrado), vuelve static_cast<std::size_t>(-1), tiendas EILSEQ en errno y deja *ps en estado indeterminado .
Original:
On conversion error (if invalid wide 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] Ejemplo

#include <iostream>
#include <vector>
#include <clocale>
#include <string>
#include <cwchar>
 
void print_wide(const wchar_t* wstr)
{
    std::mbstate_t state = std::mbstate_t();
    int len = 1 + std::wcsrtombs(NULL, &wstr, 0, &state);
    std::vector<char> mbstr(len);
    std::wcsrtombs(&mbstr[0], &wstr, mbstr.size(), &state);
    std::cout << "multibyte string: " << &mbstr[0] << '\n'
              << "Length, including '\\0': " << mbstr.size() << '\n';
}
 
int main()
{
    std::setlocale(LC_ALL, "en_US.utf8");
    // UTF-8 narrow multibyte encoding
    const wchar_t* wstr = L"z\u00df\u6c34\U0001d10b"; // or L"zß水𝄋"
    print_wide(wstr);
}

Salida:

multibyte string: zß水𝄋
Length, including '\0': 11

[editar] Ver también

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]
convierte una cadena de caracteres multibyte estrecho a la cadena de ancho, estado dado
Original:
converts a narrow multibyte character string to wide 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) [editar]
[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) [editar]
Documentación de C para wcsrtombs