Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert character type into integer type in C++?
How to convert character type into integer type in C++?

1. For character type conversion and shaping, just use forced conversion. ?

char c='B' ;

int a ;

a = (int)c ;?

If it is a character '0' to '9' are converted to 0-9

char c='8' ;

int a ;

a =(int) (c - '0') ;?

2. If converting a string to a number, use atoi or atol.

Supplementary information:

1. If you want to convert numbers to strings, you can use itoa

#include

#include < stdio.h>

int main()

{int number = 123456;

char string[25];

itoa( number, string, 10);

printf("integer = %d string = %s\n", number, string);

return 0;}