Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to convert integers into string classes or store them in character arrays in C++?
How to convert integers into string classes or store them in character arrays in C++?
Hehe, hello, landlord. Well, I generally like to deal with problems in simple but useful ways. After reading the answers upstairs, I felt good, but it was too complicated. . . Hehe, we can actually have the idea of taking out the numbers 1, 2, 3 and 4 on each digit of 1234 and storing them in the array respectively. The specific procedures are as follows:

# include & ltstdio.h & gt

Master ()

{

int a,I;

char b[ 100];

scanf("%d ",& ampa);

for(I = 0; a & gt0; a=a/ 10)

b[i++]= a % 10+48;

b[I]= 0;

for(I = I- 1; I & gt=0; I-)

printf ("%c\n ",b[I]);

}

What needs to be explained here is that the ASCII code of the number 0 is 48, and so on, so if you want to save the array correctly, you must add 48, followed by b [I] = 0;

Because all arrays must have the ending character' \ 0' (ASCII code is 0) to output normally.