Answer to Question #33848 in C++ for amit kumar
2013-08-04T03:29:00-04:00
how can i check that a string contains integer or not in c language ? please write the full program
1
2013-08-13T09:59:07-0400
#include <stdio.h> #include <iostream> #include <string> using namespace std; bool contains(string &s) { int i = 0; while (s[i] != ' ') { if (s[i] == '1' || s[i] == '2' || s[i] == '3' || s[i] == '4' || s[i] == '5' || s[i] == '6' || s[i] == '7' || s[i] == '8' || s[i] == '9' || s[i] == '0') ++i; else return false; } return true; } int main() { cout << "Enter string: "; string str; cin >> str; cout << ((contains(str) == true) ? "Your string is an integer" : "Your string is not an integer"); cin.get(); cin.get(); return 0; }
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS !
Learn more about our help with Assignments:
C++
Comments
Leave a comment