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 :: map key exists c++ 
Cpp :: c++ try catch 
Cpp :: input output c++ 
Cpp :: struct and return functions in c++ 
Cpp :: hello world c++ visual studio 
Cpp :: you wanna import math on c++ 
Cpp :: c++ set console title 
Cpp :: c++ edit another processes memory address 
Cpp :: file descriptor linux c++ 
Cpp :: ue log c++ unreal 
Cpp :: c++ get input without loop 
Cpp :: sfml mouse click 
Cpp :: c++ while loop decrement 
Cpp :: change int to string cpp 
Cpp :: creator of C++ 
Cpp :: Return multiple values from a function using pointers 
Cpp :: c++ random number generator 
Cpp :: c++ remove whitespace from string and keep the same size 
Cpp :: Area of a Circle in C++ Programming 
Cpp :: c++ find sum of vector 
Cpp :: Matrix multiply using function c++ 
Cpp :: how to sort a vector in descending order in c++ 
Cpp :: insertion sort c++ 
Cpp :: how to convert character to lowercase c++ 
Cpp :: how to read wav file in C++ 
Cpp :: if even number c++ 
Cpp :: how to copy one vector to another 
Cpp :: C++ switch cases 
Cpp :: c++ construnctor 
Cpp :: c++ std::sort 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =