cin >> switch1
tries to read in an integer. If you type d
(which can’t be converted to an int
, it doesn’t “eat” the bad input so you must clear it manually.
Try adding this to your error case:
cin.clear();
cin.ignore(INT_MAX, '\n');
More Related Contents:
- What are the basic rules and idioms for operator overloading?
- What is the copy-and-swap idiom?
- How can I print a list of elements separated by commas?
- What happens if you call erase() on a map element while iterating from begin to end?
- Object destruction in C++
- constexpr and initialization of a static const void pointer with reinterpret cast, which compiler is right?
- How do I write a range pipeline that uses temporary containers?
- Does true equal to 1 and false equal to 0? [duplicate]
- std::map emplace without copying value
- QtCore.QObject.connect in a loop only affects the last instance
- Parsing Command Line Arguments in C++? [closed]
- Building multiple binaries within one Eclipse project
- Are parent class constructors called before initializing variables?
- Can a cast operator be explicit?
- Can i use nested loops with vectors in cpp?
- How to use boost preprocessor to generate accessors?
- Function clrscr in C and C++
- C++ Structure Initialization [duplicate]
- Near constant time rotate that does not violate the standards
- How can an incomplete type be used as a template parameter to vector here?
- c++ sizeof(array) return twice the array’s declared length
- Undefined behavior causing time travel
- When Does Move Constructor get called?
- How do I use the MinGW gdb debugger to debug a C++ program in Windows?
- Why must I put a semicolon at the end of class declaration in C++?
- sprintf for unsigned _int64
- Unable to read frames from VideoCapture from secondary webcam with OpenCV
- signal handler function in multithreaded environment
- Why does (i|o)fstream take a const char* parameter for a file name?
- Is it possible to have a pointer literal?