Home > Back-end >  Of the new questions
Of the new questions

Time:10-23

C + +, what can be read a number a number to an integer don't know the specific size?
Enter 1234567, for example, I hope to put this number 7 in the array respectively

CodePudding user response:

When the letter read, char ch=getchar (); Or cin & gt;> Ch;
Int n=ch - '0'; Thus from character transformed into digital
To put it in the array can

A predefined array greatly, enough to accommodate enough
The key is you don't know how long the input problem, s much array right?
If you know how long is the longest, it directly define the maximum length of the array
If you don't know, is about to the vector

#include
Vector Ary.
After read the letter, into digital ary. Push_back (n); Added to the array go inside

CodePudding user response:

It is better if can use the string
Defines figures, otherwise it'll have to save again
  • Related