Espacios de nombres
Variantes
Acciones

std::strtol, std::strtoll

De cppreference.com
< cpp‎ | string‎ | byte
 
 
 
 
Definido en el archivo de encabezado <cstdlib>
long      strtol(constchar*str, char**str_end, int base );
longlong strtoll(constchar*str, char**str_end, int base );
(desde C++11)
Interpreta un valor entero en una cadena de bytes que apunta str .
Original:
Interprets an integer value in a byte string pointed to by str.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

La función descarta cualquier carácter en blanco hasta que se encuentra el primer carácter que no es carácter en blanco. Entonces toma tantos caracteres como sea posible para formar una representación válida de número entero de base-n (donde n=base) y los convierte a un valor entero . El valor entero válido consiste en las siguientes partes:

  • (opcional) Signo más (+) o menos (-)
  • (opcional) Prefijo (0) que indica la base octal (se aplica cuando la base es 8)
  • (opcional) Prefijo (0x o 0X) que indica la base hexadecimal (se aplica cuando la base es 16)
  • Una secuencia de dígitos

El conjunto de valores válidos para base es {0,2,3,...,36}. El conjunto de dígitos válidos para enteros de base 2 es 01, para enteros de base 3 es 012, y así sucesivamente. Para bases mayores que 10, los dígitos válidos incluyen caracteres alfabéticos, empezando desde Aa para enteros de base 11, hasta Zz para enteros de base 36. Los caracteres alfabéticos pueden ser minúsculas o mayúsculas.

Pueden aceptarse formatos numéricos adicionales por la configuración regional de C actualmente instalada.

Si el valor de base es 0, la base numérica se detecta automáticamente: si el prefijo es 0, la base es octal, si el prefijo es 0x o 0X, la base es hexadecimal, de lo contrario la base es decimal.

Si el signo menos era parte de la secuencia de entrada, el valor numérico calculado a partir de la secuencia de dígitos se niega como si lo fuera por el menos unario en el tipo del resultado

Las funciones establece el puntero que apunta str_end para que apunte al carácter allá del último carácter interpretado. Si str_end es NULL, se omite .
Original:
The functions sets the pointer pointed to by str_end to point to the character past the last character interpreted. If str_end is NULL, it is ignored.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si el str está vacía o no tiene la forma esperada, no se realiza la conversión, y (si es str_end no NULL) el valor de str se almacena en el objeto apuntado por str_end .
Original:
If the str is empty or does not have the expected form, no conversion is performed, and (if str_end is not NULL) the value of str is stored in the object pointed to by str_end.
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

str -
puntero a la cadena terminada en null byte debe ser interpretado
Original:
pointer to the null-terminated byte string to be interpreted
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
str_end -
puntero a un puntero a caracter .
Original:
pointer to a pointer to character.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
base -
Base del valor entero interpretado
Original:
base of the interpreted integer value
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 tiene éxito, un valor entero correspondiente al contenido de str se devuelve .
    Original:
    If successful, an integer value corresponding to the contents of str is returned.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Si el valor convertido cae fuera del rango de tipo de retorno correspondiente, un error de rango se produce (ajuste [[cpp/error/errno|errno]] a ERANGE) y LONG_MAX, LONG_MIN, LLONG_MAX o LLONG_MIN se devuelve .
    Original:
    If the converted value falls out of range of corresponding return type, a range error occurs (setting [[cpp/error/errno|errno]] to ERANGE) and LONG_MAX, LONG_MIN, LLONG_MAX or LLONG_MIN is returned.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • Si la conversión no se puede realizar, 0 se devuelve .
    Original:
    If no conversion can be performed, 0 is returned.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.

[editar]Ejemplo

[editar]Ver también

Convierte una cadena de bytes en un valor entero.
(función)[editar]
Convierte una cadena de bytes en un valor entero sin signo.
(función)[editar]
Documentación de C para strtol, strtoll
close