Given a string consisting of a single character followed by a number (one or two digits), I would like to split it into a character and an integer. What is the easiest way to accomplish this?
My thoughts so far:
I can easily grab the character like so:
string mystring = "A10";
char mychar = mystring[0];
The hard part seems to be grabbing the one or two digit number that follows.
You can make use of the operator[], substr, c_str and atoi as:
EDIT:
The above will also work if
s="A1". This is because if the2ndargument tosubstrmakes the substring to span past the end of the string content, only those characters until the end of the string are used.