Checking if String is an int : <p>I'm trying to enter the format of </p>

<blockquote>
  <p>"prog1 1 all file1"  </p>
</blockquote>

<p>the first input has to be a argv[1] should be an int.</p>

<p>So i need a way to determine if argv[1] is entered as a string "xxx" ( "prog1 xxx" ) it should return "NO PHRASE LENGTH" but its returning "INVALID PHRASE LENGTH". </p>

<p>I see there is a isdigit() function but im not sure how i would use that.</p>

<pre><code>int main(int argc, char *argv[]){


try{
if(argc == 1){

   cout &lt;&lt; "NO PHRASE LENGTH" &lt;&lt; endl;  exit(1); 
}
else if((stoi(argv[1])) &lt;= 0 ){ 

    cout &lt;&lt; "INVALID PHRASE LENGTH" &lt;&lt; endl;  exit(1); 
}
else if(argc == 2){

   cout &lt;&lt; "NO MODE" &lt;&lt; endl;  exit(1); 
}
else if(!(std::string(argv[2]) == "all") &amp;&amp; !(std::string(argv[2]) == "top")){

    cout &lt;&lt; "INVALID MODE" &lt;&lt; endl;
}
else if(argc == 3){

    cout &lt;&lt; "NO FILES GIVEN" &lt;&lt; endl;
}
else if(argc &gt;= 4){


    ifstream f;
    for(int i = 4; i &lt; argc; i--){

        f.open( argv[i] );

        if( ! f.good() ) { 
            cout &lt;&lt; "BAD FILE " &lt;&lt; argv[i] &lt;&lt; endl; exit(1); 
        }

        //cout &lt;&lt; "OK" &lt;&lt; endl;
        //f.close();

    }




}
else
    return 0;
}
catch(exception e){
}} 
</code></pre>
