checking an int in c++
C++
// CPP program to check if a given string
// is a valid integer
#include <iostream>
using namespace std;
// Returns true if s is a number else false
bool isNumber(string s)
{
for (int i = 0; i < s.length(); i++)
if (isdigit(s[i]) == false)
return false;
return true;
}
// Driver code
int main()
{
// Saving the input in a string
string str = "6790";
// Function returns 1 if all elements
// are in range '0-9'
if (isNumber(str))
cout << "Integer";
// Function returns 0 if the input is
// not an integer
else
cout << "String";
}
Also in C++:
- Title
- declaration vs. definition cpp
- Category
- C++
- Title
- getline not working c++
- Category
- C++
- Title
- c++ reset stream
- Category
- C++
- Title
- c++ isalphanum
- Category
- C++
- Title
- switch c++
- Category
- C++
- Title
- c++ code 2d block
- Category
- C++
- Title
- nth_element c++
- Category
- C++
- Title
- C++ user input
- Category
- C++
- Title
- how to convert string into number
- Category
- C++
- Title
- c++ for loop syntax
- Category
- C++
- Title
- preorder traversal
- Category
- C++
- Title
- switch statement c++
- Category
- C++
- Title
- c++ declare char
- Category
- C++
- Title
- capitalize first letter c++
- Category
- C++
- Title
- gfg left view of tree
- Category
- C++
- Title
- in c, is class uppercase or lowercase
- Category
- C++
- Title
- c++ switch case statement
- Category
- C++
- Title
- find_if c++ example
- Category
- C++
- Title
- dfs in c++
- Category
- C++
- Title
- RLE Encoding/Compression c++
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- visual studio 2019 read and write text file c++
- Category
- C++
- Title
- C++ pointer arithmetic
- Category
- C++
- Title
- calling by reference c++
- Category
- C++
- Title
- sum of two numbers c++
- Category
- C++
- Title
- variabvles in c++
- Category
- C++
- Title
- how to find hcf in c++
- Category
- C++
- Title
- cpp pi from acos
- Category
- C++
- Title
- pause the console c++
- Category
- C++
- Title
- int random string generator c++
- Category
- C++
- Title
- Application of c++ in youtube program
- Category
- C++
- Title
- C++ remove element from set
- Category
- C++
- Title
- c++ do you not inherit constructor
- Category
- C++
- Title
- how to make string get spaces c++
- Category
- C++
- Title
- how to decalre a string in c++
- Category
- C++
- Title
- binary search in set c++
- Category
- C++
- Title
- how to get a letter from the user c++ string
- Category
- C++
- Title
- extends c++
- Category
- C++
- Title
- c++ string to vector int
- Category
- C++
- Title
- copy a part of a vector in another in c++
- Category
- C++
- Title
- can we compare a long long int with int in c++ using max or min functions
- Category
- C++
- Title
- log base e synthax c++
- Category
- C++
- Title
- C++ If
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- c++ dereference a pointer
- Category
- C++
- Title
- c++ overloaded equality check operator
- Category
- C++
- Title
- char **
- Category
- C++
- Title
- rosrun actionlib_msgs genaction.py
- Category
- C++
- Title
- rand c++
- Category
- C++
- Title
- variadic templates
- Category
- C++
- Title
- else if c++
- Category
- C++
- Title
- initialize vector of vector c++
- Category
- C++
- Title
- int max in c++
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- pionter in c++
- Category
- C++
- Title
- how to use a new node c++
- Category
- C++
- Title
- file objects in c++
- Category
- C++
- Title
- first prime numbers less than
- Category
- C++
- Title
- find in set of pairs using first value cpp
- Category
- C++
- Title
- how to sort in descending order c++
- Category
- C++
- Title
- set of vectors c++
- Category
- C++
- Title
- c++ how to skip the last element of vector
- Category
- C++
- Title
- max heap c++ stl;
- Category
- C++
- Title
- vertical traversal of binary tree
- Category
- C++
- Title
- double to int c++
- Category
- C++
- Title
- c++ compare char array
- Category
- C++
- Title
- how to iterate through a map in c++
- Category
- C++
- Title
- printf c++
- Category
- C++
- Title
- system("pause") note working c++
- Category
- C++
- Title
- array sort c++
- Category
- C++
- Title
- equal elements in two arrays in c++
- Category
- C++
- Title
- how can make string value in cpp
- Category
- C++
- Title
- pyqt connect
- Category
- C++
- Title
- Convert binary tree to a doubly linked list
- Category
- C++
- Title
- how to create object in c++
- Category
- C++
- Title
- how to create a vector in c++
- Category
- C++
- Title
- hashset in c++
- Category
- C++
- Title
- hashmap in c++
- Category
- C++
- Title
- factorial in c++
- Category
- C++
- Title
- coping 2d vector in cpp
- Category
- C++
- Title
- c++ find prime numbers
- Category
- C++
- Title
- c++ string contains
- Category
- C++
- Title
- how to initialize an struct object in c++
- Category
- C++
- Title
- never gonna give you up
- Category
- C++
- Title
- c++ while loop code
- Category
- C++
- Title
- pop from between string c++
- Category
- C++
- Title
- map vs unordered_map in C++
- Category
- C++
- Title
- find vector in c++
- Category
- C++
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- bitset c++
- Category
- C++
- Title
- euler phi gfg
- Category
- C++
- Title
- append string to another string c++
- Category
- C++
- Title
- c++ overload operator
- Category
- C++
- Title
- getch c++ library
- Category
- C++
- Title
- fmod c++
- Category
- C++
- Title
- size of a matrix using vector c++
- Category
- C++
- Title
- c++ variable argument
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- checking an int in c++
- Category
- C++