Hey guys , i would like to ask some question regarding checking if a string is all integer. First off, i wrote a program to check if the value i enter contains strings.
string str;
int n = 0 ;
cout << "Enter the letter please "<< endl;
cin >> str;
const char* fd = str.c_str ();
// for(int i=0;i<str.length();i++)
if (isdigit(fd[n]))
{
n++; }
else
{
cout <<"Not all are numbers"<< endl;
}
}
My expected output is if the string only hold integers (0-9) , it will then print the string out. if not , it will print another message telling me it does not contain numbers only.
I tried running my coding. but it does not seem to be able to work when i input in information such as "12d".
Hope for some help here and if you all know a better way to check , please guide me. Thanks!