验证字符串是否为全部数字

OPJ*_*OPJ -1 c++ string

嗨,我无法验证这个字符串是否为全部小数,即使我输入9999它仍然告诉我我的if语句出错.我认为这是一个错字,但我不知道在哪里.

cout<<"Enter a very large number"<<endl;
cin>>In1;                            //inputs a string
for(int i=0; 0<In1.length();i++){    //the loop that goes thru each index
    if (!(isdigit(In1[i]))){         //validates each index
        //tells the user to try again
        cout<<"You did not enter a valid input, please try again"<<endl;
        In1="";
        cin>>In1;
        i=0;//starts the loop over if reached
    }
}
Run Code Online (Sandbox Code Playgroud)

我一直收到"你没有输入有效的输入,请再试一次",无论我输入是对还是错.

Kun*_*nal 5

for(int i=0; 0<In1.length();i++){
Run Code Online (Sandbox Code Playgroud)

看看你做了什么?改成

for(int i=0; i<In1.length();i++)
Run Code Online (Sandbox Code Playgroud)

在你的循环状况,你需要比较iIn1.length().