Search code examples
c++charinttypeconverter

Converting char to int '23' > 23


I have seen so many post of how to convert a single digit into an int, but how i can convert more than one digit number into a int, just like '23' convert it to 23;


Solution

  • To convert a char array to an integer, use atoi(). If converting strings, add .c_str() after the string variable to convert it into a suitable form for use.

    You can also use stoi(), which provides some additional features for conversion, such as specifying the base.