哪位大虾帮我改改啊..到底哪错了啊
#include "stdafx.h"
#include "iostream.h"
#include "string"
using namespace std;
struct car
{
string maker;
string years;
} cars;
int main(int argc, char* argv[])
{
int i,sum;
cout << "How many cars do you wish to cataog?\t";
cin >> sum;
cars *pc = new cars[sum];
for(i=0;i<sum;i++)
{
cout << "Car #" << i <<":\n"
<< "Please enter the make:";
cin >> pc[i]->maker;
cout << "Please enter the year made:";
cin >> pc[i]->years;
}
cout << "Here is your collection:\n";
for(i=0;i<sum;i++)
{
cout << pc[i]->years <<'/t'<<pc[i]->maker<<endl;
}
delete p;
return 0;
}
[解决办法]
pc[i]- >make; -> pc[i].maker; //其它同
delete p; -> delete []pc;
[解决办法]
#include <iostream>#include <string> using namespace std; typedef struct car { string maker; string years; }cars; int main(int argc, char* argv[]) { int i,sum; cout << "How many cars do you wish to cataog?\t"; cin >> sum; cars *pc = new cars[sum]; for(i=0;i <sum;i++) { cout << "Car #" << i <<":\n" << "Please enter the make:"; cin >> pc[i].maker; cout << "Please enter the year made:"; cin >> pc[i].years; } cout << "Here is your collection:\n"; for(i=0;i <sum;i++) { cout << pc[i].years << '/t ' <<pc[i].maker <<endl; } delete pc; return 0; }