string to int

string to int

c++

std::stoi (C++11)

  • Convert string to unsigned integer
    1
    2
    unsigned long stoul (const string&  str, size_t* idx = 0, int base = 10);
    unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
  • param
    • str
      • String object with the representation of an integral number.
    • idx
      • Pointer to an object of type size_t, whose value is set by the function to position of the next character in str after the numerical value.
      • This parameter can also be a null pointer, in which case it is not used.
    • base
      • Numerical base (radix) that determines the valid characters and their interpretation.
      • If this is 0, the base used is determined by the format in the sequence (see strtol for details). Notice that by default this argument is 10, not 0.

        std::from_chars (c++17)

        strtoul

  • Interprets an unsigned integer value in a byte string pointed to by str.
    1
    unsigned long      strtoul( const char *str, char **str_end, int base );
  • params
    • str
      • pointer to the null-terminated byte string to be interpreted
    • str_end
      • pointer to a pointer to character.
    • base
      • base of the interpreted integer value

        c

        atoi()

        • <stdlib.h>

reference