int SelectedIndex;
int i = 4;
while(SelectedIndex > i-1 || SelectedIndex < 0)
{
try{
std::cout <<"please input index from 0 to " << i-1 << std::endl;
std::cin >> SelectedIndex;
}
catch(std::exception& e){SelectedIndex = 999;}
}
Why such loop does not catch error when inputting a string? How to fix it? I can use std::string and Boost library and reg exp.