text: Program to check if input is an integer or a string | CPP program to check if a given string is a valid integer ; Returns true if s is a number else false ; Driver code ; Saving the input in a string ; Function returns 1 if all elements are in range '0-9' ; Function returns 0 if the input is not an integer
code: #include <iostream> NEW_LINE using namespace std ; bool isNumber ( string s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( isdigit ( s [ i ] ) == false ) return false ; return true ; } int main ( ) { string str = "6790" ; if ( isNumber ( str ) ) cout << " Integer " ; else cout << " String " ; }