【发布时间】:2010-11-28 01:22:40
【问题描述】:
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;}
}
为什么这样的循环在输入字符串时不会捕获错误? 如何解决?我可以使用 std::string 和 Boost 库和 reg exp。
【问题讨论】:
-
1. SelectIndex 未初始化。 2. 你能解释一下你想要发生的事情,以及实际发生的事情吗?
标签: c++ visual-studio visual-studio-2008 boost