我不确定它是否是另一个答案中提到的错误,但不知何故catch块在处理异常一次后改变/省略了temp的内容。下面的代码解决了这个问题。制作
temp
一个
const
解决这个问题。
#include <iostream>
int main()
{
const std::string temp("exception");
int value;
while(std::cin>> value && value != 0)
{
try{
if(value > 9) throw temp;
else std::cout << value << "\n";
}
catch(std::string temp){
std::cerr << temp << "\n";
}
}
return 0;
}
</code>