Start here · Essential guide
How to Convert a Char to an Int in C++
Learn how to convert a char to an int in C++. Get a character's numeric code, turn the digit '7' into the number 7, and avoid the most common mistakes.
Strings, Containers and Memory
How to convert a char to an int, how big a char is and how to_string helps.
Start here · Essential guide
Learn how to convert a char to an int in C++. Get a character's numeric code, turn the digit '7' into the number 7, and avoid the most common mistakes.
Yes, sizeof(char) is always 1 in C. The number of bits in that byte is set by CHAR_BIT, which is 8 on most systems. Here is what that means in practice.
%d is the printf format for int values and %f is the format for floating-point values like double. Here is how each one works, with a short C example.
std::to_string turns a number into a std::string. It works for ints, doubles and chars, but a double like 3.14 becomes 3.140000 and a char gives its code.
Related topics