注册 登录
编程论坛 新人交流区

[求助] 两个程序一模一样。为什么有一个不能通过编译

fibers 发布于 2007-10-03 17:21, 799 次点击

我写了两个程序。。是一模一样的。。但是有一个编译的时候能通过。。另一个不能。
这个是能通过编译的:
#include <iostream>
struct car
{
char name[20];
int year;
};
int main(void)
{
using namespace std;
int n;
cout << "How many cars do you wish to catalog?: ";
cin >> n;

car * pc = new car [n];
int i;
for (i = 0; i < n; i++)
{
cout << "Car #" << (i + 1) << ":\n";
cout << "Please enter the make: ";
cin.getline(pc[i].name,20);
cout << "Please enter the year made: ";
cin >> pc[i].year;

}
cout << "Here is your collection:\n";
for (i = 0; i < n; i++)
cout << pc[i].year << " " << pc[i].name << "\n";
delete [] pc;
return 0;
}


这个是不能通过编译的:
#include<iostream>
struct car
{
char name[20];
int year;
};
int main(void)
{
using namespace std;
int n;
cout << "How many cars do you wish to catalog?: ";
cin >> n ;
car* pc = new car[n];
int i;
for (i = 0; i < n; i++)
{
cout << "Car #" << (i + 1) << ":\n";
cout << "Please enter the make: ";
cin.getline(pc[i].name,20);
cout << "Please enter the year made: ";
cin >> pc[i].year;

}
cout << "Here is your collection:\n"
for (i=0 ; i<n ; i++)
cout << pc[i].year << " " << pc[i].name << "\n";
delete [] pc;
return 0 ;
}

这个没能通过编译的程序,显示:
Error E2379 10.cpp 25: Statement missing ; in function main()
Error E2379 10.cpp 25: Statement missing ; in function main()

19 回复
#2
风月_无边2007-10-03 17:32
你不是開玩笑嗎
#3
lu_wei2007-10-03 17:33
倒数第五行少了个;号
#4
杨子鹅2007-10-03 17:37
恩。。果然啊。。。
#5
dongbo192007-10-03 19:21
gou zi xi a
#6
ygh4494977112007-10-03 19:46
把3楼说的;加上就没问题啦,我使用的是vs2005
两个程序结果完全一样,都没问题
#7
dgwdgw2007-10-03 21:21
楼上说的对,是倒数第五行少了个;号
#8
xiaotianshen2007-10-03 21:29
呵呵,这个编译的时候应该会有提示吧,怎么不仔细看看啊
#9
greatyollow2007-10-04 07:58
#10
liuzusheng2007-10-04 08:24
我初学,很讨厌“;”这样一个东西的!
#11
wuquan2007-10-04 10:59

就是啊,少了个;号啊,编译结果都有提示了啊

#12
qiuzhihao2007-10-06 15:57
#13
sam072007-10-06 16:13
倒数第5行少了个;
#14
zamboninite2007-10-06 16:14
; 惹的祸
#15
scutan2007-10-06 16:39
以下是引用liuzusheng在2007-10-4 8:24:24的发言:
我初学,很讨厌“;”这样一个东西的!

这是C/C++语法, 得遵守的.

#16
hyundaiA2002007-10-06 16:42
来看看~~~~~~~~~~~~~~~~~~~~~
#17
zhengtianyan2007-10-06 17:55
#18
lzys2007-10-07 14:29
晕了,,,我根本就看不懂....不知道该从哪学起!!!!!!!!!!!!
#19
王振兴2007-10-07 16:15
慢慢来就是了,急不得!
#20
succubus2007-10-07 16:21
难道lz都不看编译器的提示信息的吗?
1