首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

麻烦给看看这段程序的异常~

2012-03-25 
麻烦给看看这段程序的错误~~C/C++ code#include iostream#include stdio.h#include exceptionusing

麻烦给看看这段程序的错误~~

C/C++ code
#include <iostream>#include <stdio.h>#include <exception>using namespace std;int main(){    char str[20];    gets(str);    if (*str > '0' && *str < '9')    {        cout << str << endl;    }    else    {        try        {            throw runtime_error("首字母不是数字,重新输入") << endl;        }        catch (runtime_error &err)        {            cout << err.what();        }    }    return 0;}


抛出异常部分有错

[解决办法]
throw runtime_error("首字母不是数字,重新输入") << endl;
将上面这一句修改为:
throw runtime_error("首字母不是数字,重新输入");
runtime_error这个类,并没有重载输出操作符
[解决办法]
直接丢掉异常后面的输出endl就可以了

热点排行