For example, there is a string n containing "1234".
string n = "1234"
Now, there are int a, b, c, d for storing 1, 2, 3, 4 separately.
a is 1
b is 2
c is 3
d is 4
How to get those digits from string "12345" by using a standard function?
Previously, I use the following way.
int getDigit(string fourDigitString,int order)
{
std::string myString = fourDigitString;
int fourDigitInt = atoi( myString.c_str() ); // convert string fourDigitString to int fourDigitInt
int result;
int divisor = 4 - order;
result = fourDigitInt / powerOfTen(divisor);
result = result % 10;
return result;
}
Thank you for your attention