Search
 
SCRIPT & CODE EXAMPLE
 

CPP

know what the input data is whether integer or not

#include <iostream>

using std::cout;
using std::cin;
using std::endl
using std::string;

bool isNumber(const string& str)
{
    for (char const &c : str) {
        if (std::isdigit(c) == 0) return false;
    }
    return true;
}

int main(){
    string str1 = "231524randstr23";
    string str2 = "23152423";
    string str3 = "a3152423";

    isNumber(str1) ? cout << "Number
" : cout << "Not number
";
    isNumber(str2) ? cout << "Number
" : cout << "Not number
";
    isNumber(str3) ? cout << "Number
" : cout << "Not number
";

    return EXIT_SUCCESS;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: dynamic memory in c++ 
Cpp :: c++ last element of array 
Cpp :: flutter text direction auto 
Cpp :: c++ main function parameters 
Cpp :: how to set arrays as function parameters in c++ 
Cpp :: c++ structs 
Cpp :: cpp compiler online 
Cpp :: c++ constructor 
Cpp :: c++ virtual function 
Cpp :: c++ add everything in a vector 
Cpp :: C/C++ loop for 
Cpp :: c++ download 
Cpp :: recherche recursive le max dans une liste 
Cpp :: c++ the hash function with 31 const 
Cpp :: Code debut C++ 
Cpp :: uint16_t does not name a type 
Cpp :: c shortest path dijkstra 
Cpp :: nmake.exe is not found in the windows 
Cpp :: ++m in c 
Cpp :: PascalName seperate strings 
Cpp :: c++ how to use and or in if 
Cpp :: overload operator object function call 
Cpp :: what do I return in int main() function c++ 
Cpp :: vector literal in cpp 
Cpp :: omp multiple reductions 
Cpp :: Corong_ExerciseNo3(1) 
Cpp :: fibonacci sequence c++ 
Cpp :: hpp files 
Cpp :: accepting multiple values from a function in cpp 
Cpp :: C++ if...else 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =