雅典奥运会歌曲:懂一点点c++的帮忙

来源:百度文库 编辑:高考问答 时间:2024/05/06 10:05:50
下面是一个演示c++异常处理机制的小程序,我照书上抄的,但是compile后有如下错误提示:--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Documents and Settings\s1.C00\桌面\Cpp1.cpp(30) : error C2601: 'inputdata' : local function definitions are illegal
C:\Documents and Settings\s1.C00\桌面\Cpp1.cpp(43) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Cpp1.obj - 2 error(s), 0 warning(s)
下面是源程序
#include <iostream.h>
#include <ctype.h>
int inputdata(void);
int main()
{
int value;
int continueflag=1;
cout<<"~~~exception handing~~~"<<endl;
while (continueflag)
{
try{
value=inputdata();
cout<<"you enter"<<value<<".everything is fine."<<endl;
continueflag=0;
}
catch (int zero){
cerr<<zero<<"is not valid"<<endl;
}
catch (const char *message){
cerr<<message<<endl;
}
catch (...){
cerr<<"donot konw what you enter!"<<endl;
}
cout <<"end of my act !:-)";
return 0;
}

int inputdata(void)
{
int userdata;
cout<<"enter a number:";
cin>>userdata;
if (userdata==0)
throw 0;
else if (userdata<5)
throw("number is too low");
else if (userdata>15)
throw("number is too high");
return (userdata);
}

仔细检查你的程序.

cout <<"end of my act !:-)";
return 0;
}
后面漏掉了半个大括号,导致
int inputdata(void)
被误写入了主函数中,只要在
cout <<"end of my act !:-)";
return 0;
}
后面再加个}就可以了呵呵
是你抄错了.
建议以后可以把大括号分层配对,把同层的大括号放在一个垂直线上
方便查找错误.

大哥这是懂一点点能看懂的吗!?