写编程练习,运行异常,不知道问题在哪,求大佬
#include<iostream>#include<string>
using namespace std;
struct car { string name; int year; };
int main() {
cout << "How many cars do you wish to catalog?";
int a;
cin >> a;
cin.get();
car* A = new car[a];
for (int i = 0; i <= a; i++) {
cout << "Car #" << i + 1 << ":" << endl;
cout << "Pleaseenter the make:";
getline(cin, A[a].name);
cout << "Please enter the year made:";
cin >> A[a].year;
cin.get();
};
cout << "Here is your collection:" << endl;
for(int j=0;j<=a;j++)
cout << A[j].year << " " << A[j].name << endl;
delete[] A;
return 0;
}
输入int值a之后提示异常:
引发了异常: 写入访问权限冲突。
**_Left** 是 0x51EE1DC。
这是哪出问题了,语句写的不对么?
[此贴子已经被作者于2020-1-16 19:32编辑过]