Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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;
    }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #user #inputs #int
ADD COMMENT
Topic
Name
5+6 =