How can I convert a string to int and char, with fixed number of positions, in C++? For example: I need to convert "A1920139" into char "A", int 192 (next three positions in the string), int 01 (following two positions), and int 39 (last two positions).
So far I have only managed to get each int by itself (1, 9, 2, 0, etc). I don't know how to get the char or define a fixed number of positions for the int. This is what I have managed to write:
string userstr;
int* myarray = new int[sizeof(userstr)];
userstr = "A1920139";
for (i = 1; i < userstr.size(); i++) {
myarray[i] = userstr[i] - '0';
}
for (i = 1; i < userstr.size(); i++) {
printf("Number %d: %d\n", i, myarray[i]);
}
Eventually I need to arrive at something like char="A"
, int_1=192
, int_2=01
, and int_3=39