Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to make sure the user inputs a int and not anything else c++

int x;
    std::cin >> x;
    while(std::cin.fail()) {
        std::cout << "Error" << std::endl;
        std::cin.clear();
        std::cin.ignore(256,'
');
        std::cin >> x;
    }
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ print hello world 
Cpp :: struct and pointers (retun function) in c++ 
Cpp :: priority queue ordered by second element 
Cpp :: c++ allocate and free dynamic 2d array 
Cpp :: sony pictures animation films produced 
Cpp :: cpp how to input a variable without hitting enter 
Cpp :: c++ celsius to fahrenheit 
Cpp :: arduino get size of array 
Cpp :: constant pointer c++ 
Cpp :: write a code that adds two number 
Cpp :: gmod hitman job code 
Cpp :: c++ for loop 
Cpp :: time measurement c++ 
Cpp :: integer to string c++ 
Cpp :: factore of 20 in c+ 
Cpp :: regex for phone number c++ 
Cpp :: c++ rand() 
Cpp :: use regex replace in c++ 
Cpp :: crypto npm random bytes 
Cpp :: cout.flush() in c++ 
Cpp :: quadratic problem solution c++ 
Cpp :: format c++ discord 
Cpp :: how to change string to lowercase and uperCase in c++ 
Cpp :: how to get input in cpp 
Cpp :: capitalize first letter c++ 
Cpp :: how to use string variable in switch case in c++ 
Cpp :: how to split a string into words c++ 
Cpp :: c++ code for quicksort 
Cpp :: c++ constructors 
Cpp :: c++ vector fill 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =