How to check if argv contains a letter

Write your question here.
if the command argument was 123abc3, how would check for the letters in that argument and cout an error, really struggling and dont know where to start
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>

int main( int argc, char* argv[] )
{
    for( int i = 0 ; i < argc ; ++i )
    {
        std::cout << i << ". '" << argv[i] << "' " ;

        try
        {
            const std::string str = argv[i] ;
            std::size_t pos ;
            // http://en.cppreference.com/w/cpp/string/basic_string/stol
            const int value =  std::stoi( str, &pos, 10 ) ; // decimal integer literal
            if( pos == str.size() ) std::cout << "integer value is " << value << '\n' ;
            else std::cout << "partial conversion to int; value: " << value << " (non-numeric character found at position " << pos << ")\n" ;
        }
        
        catch( const std::invalid_argument& ) { std::cout << "invalid characters: no conversion could be performed\n" ; }
        
        catch( const std::out_of_range& ) { std::cout << "integer value is out of the range of int\n" ; }
    }
}

http://coliru.stacked-crooked.com/a/75610594ad15464c
Topic archived. No new replies allowed.