Le'Internationale 2017-07-24 15:18 采纳率: 0%
浏览 1039

c++报错 文件名.exe已停止工作

#include "stdafx.h"
#include
#include
using namespace std;

int main()
{
struct car {
string name;
int year;
};
int i = 0, j = 0;
cout << "how many cars do you want to catalog ?" << endl;
cin >> i;
car *cars = new car[i];
cin.get();
for (j = 0; j <= i; j++) {
cout << "please enter the make: ";
getline(cin, cars[i].name);
cout << "please enter the year: ";
cin >> cars[i].year;
cin.get();
}
cout << "here is your collection: " << endl;
for (j = 0; j <= i; j++) {
cout << "nmae: " << cars[i].name << endl;
cout << "year: " << cars[i].year << endl;
cout << endl;
}
delete []cars;
return 0;
}
运行这段代码后显示文件已停止工作
请问如何解决

  • 写回答

2条回答 默认 最新

  • _cycycyc 2017-07-25 02:21
    关注

    j <= i改成j < i

    下标范围是0到i-1

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?