Horje
c++ check if cin got the wrong type Code Example
c++ check if cin got the wrong type
while (std::cout << "Enter a number" && !(std::cin >> num)) {
    std::cin.clear(); //clear bad input flag
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); //discard input
    std::cout << "Invalid input; please re-enter.\n";
}




Cpp

Related
cplusplus Code Example cplusplus Code Example
how to make c++ read strlen Code Example how to make c++ read strlen Code Example
c++ Greatest common divisor Code Example c++ Greatest common divisor Code Example
Remove Linked List Elements leetcode Code Example Remove Linked List Elements leetcode Code Example
c++ if else Code Example c++ if else Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8