-
Notifications
You must be signed in to change notification settings - Fork 0
debug.h ~ debug ~ verify
Baptiste Thémine edited this page Apr 27, 2023
·
9 revisions
bool debug::verify(std::istream &ios) noexcept;
Checks and clears I/O state then flushes input stream.
Typical usage of this function is to apply user input validation inside a loop.
-
ios
--> reference to an istream object.
Returns true if input stream has no errors otherwise returns false.
Never throws exception.
In the following example, we loop until user input is a valid integer.
#include <iostream>
#include <JLC/debug.h>
int main(){
int num;
do{
std::cout << "num = ";
std::cin >> num;}
while(!debug::verify(std::cin));
std::cout << num << std::endl;
}
num = test
num = 42
42