Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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(), '
'); //discard input
    std::cout << "Invalid input; please re-enter.
";
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: C/C++ loop for 
Cpp :: summation of numbers using function 
Cpp :: fname from FString 
Cpp :: pthread c++ example with output 
Cpp :: InstallUtil.exe ConsoleApp 
Cpp :: recuva recovery software for pc with crack 
Cpp :: function for reversing an array c++ stl 
Cpp :: wgat is duble in c++ 
Cpp :: end vs cend in cpp 
Cpp :: c++ file handiling 
Cpp :: memset array bool 
Cpp :: full pyramid in c++ 
Cpp :: sort array in descending order c++ 
Cpp :: c++ vector move element 
Cpp :: how to code a game in c++ 
Cpp :: C++ for vs while loops 
Cpp :: long, long long 32 bit or 8 bit in c++ 
Cpp :: linq select where string equals "String" 
Cpp :: codeforces problem 1700A solution in c++ 
Cpp :: Check whether K-th bit is set or not c++ 
Cpp :: find node from pos linkedlist c++ 
Cpp :: c++ system() from variable 
Cpp :: KUNG FU HUSTLE 
Cpp :: sfml hide message 
Cpp :: output sum of a range 
Cpp :: copying a file to an array and sorting 
Cpp :: high school hacking competition 
Cpp :: c++ copy with transform 
Cpp :: draw point sfml 
Cpp :: c++ synchronization primitives example programs 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =