作者suhue (丰风)
看板Programming
标题[问题] C++ try-catch语法
时间Mon Sep 24 13:40:58 2007
我想请问我写的try-catch语法有没有错误,
因为每次compile时,总是出现那行expression syntax的错误
可是找不出问题出在哪,我已经照课本上的方式写了
能不能请大家帮我看一下
#include<iostream.h>
void main()
{ int n;
int a[5]={1,2,3,4,5};
cout<<"n="<<endl;
cin>>n;
try{ if(n<0) -------------------->expression syntax
throw "invalid number n";
int s=0;
for(int i=0;i<n;i++)
s=s+a[i];
cout<<"sum="<< s<<endl;
}
catch(char *e)
{
cout<<e<<endl;
};
};
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.31.174.119
1F:→ StubbornLin:首先要改的是你的缩排125.231.227.138 09/24 14:06
2F:→ suhue:请回答重点好吗? 61.31.174.119 09/24 14:17
3F:→ suhue:我使用BCB,不知道工具是否有差? 61.31.174.119 09/24 14:18
4F:推 sunneo:完全无差220.132.228.138 09/24 15:15
6F:→ sunneo:那是一个clpstr,所以请catch(const char*e)220.132.228.138 09/24 15:25
7F:→ sunneo:说真的,缩排真的很糟220.132.228.138 09/24 16:09
8F:→ suhue:对不起,为什麽我复制你的程式再用BCB run 61.31.174.119 09/24 19:09
9F:→ suhue:结果还是错误一堆? 61.31.174.119 09/24 19:09
10F:→ suhue:我的缩排好像只有一个地方没对齐而已吧!哪糟 61.31.174.119 09/24 19:10
11F:推 wowtiger:第一次看到缩排是这样缩的XD 有创意 218.163.100.85 09/24 19:56
12F:→ sunneo:何不把所谓更多的错误讯息po出来看看?220.132.228.138 09/24 21:31
13F:→ sunneo:去C/CPP问看看吧...我转过去220.132.228.138 09/24 21:36
※ sunneo:转录至看板 C_and_CPP 09/24 21:36
14F:→ sunneo:何不检查专案是否正确?副档名...220.132.228.138 09/24 21:49
15F:推 sunneo:只有一个地方没对齐吗?220.132.228.138 09/24 22:35
16F:→ sunneo:try的end scope, catch为什麽空一行?220.132.228.138 09/24 22:36
17F:→ sunneo:依照你的规则,应该是{後面空两个空白开始220.132.228.138 09/24 22:37