Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert a character into an integer in c++?
How to convert a character into an integer in c++?
1, the transformation and shaping of character types can be completed by coercion. ?

char c = ' B

int a;

a =(int)c; ?

If the characters "0" to "9" are converted to 0-9.

char c = ' 8

int a;

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

2. If it is a string of numbers, use atoi and atol.

Supplement:

1, if the number string can use itoa.

# include & ltstdlib.h & gt

# include & ltstdio.h & gt

int main()

{ int number = 123456;

char string[25];

Itoa (number, string,10);

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

Returns 0; }