string str = "A1B3Apple35C8";
for(int i = 0; i<str.size(); i++)
if(isalpha(str[i])) cout << "character " << i << " in string \"str\" is: " << str[i] << " which is a letter." << endl;
else cout << "character " << i << " in string \"str\" is: " << str[i] << " which is a number." << endl;
oh and by the way it would have to be "1" not 1 if you are doing the == because it still is a cosnt char (string) not an int. if you wish to convert it to an int you would have to do int num = atoi(choice[positionof1]);
@giblit Your code is flawed. Your if statement if(isalpha(str[i])) evaluates to true if the input is a letter. In your code anything that isn't a letter is considered a number. So the '!', '?', '.' and '@' characters are all considered numbers. Why not use the function designed specifically for the purpose of finding digits?