My c++ program asks for input of a integer type if the user inputs a character/string then the program crashes is there another method for this or another way to fix it thank you.
thekitoper
0
Newbie Poster
Recommended Answers
Jump to PostYes, you can get your input into a string and parse it.
#include <string> #include <sstream> #include <iostream> using namespace std; int main() { string input; getline(cin,input); int value = 0; stringstream(input) >> value; if(value == 0) cout << "Invalid entry." << endl; cout << value << …
All 3 Replies
pseudorandom21
166
Practically a Posting Shark
mrnutty
761
Senior Poster
pseudorandom21
166
Practically a Posting Shark
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.