array of structure using new

using namespace std;
struct car
string make;
int year;

void main()
int noOfCar;
cout<<"Enter the no. of car to cataloge: ";
car * detail = new car[noOfCar];
for(int i=0; i<noOfCar;i++)
cout<<"\ncar #"<<i++;
cout<<"\nEnter the make: ";
getline(cin, detail.make);
cout<<"\nEnter the year made: ";
for(int i =0;i<noOfCar;i++)
cout<<detail[i].year<<" "<<detail[i].make<<endl;
delete[] detail;

im getting problem with a error,
[i]Unhandled exception at 0x011A54D6 in u5ex6.exe: 0xC0000005: Access violation writing location 0xABABABAB.
and for loop
You shall not change the control variable i inside the body of the loop. So this statement

cout<<"\ncar #"<<i++;

is invalid.

You can substitute it for

cout<<"\ncar #"<<i + 1;
Last edited on
Topic archived. No new replies allowed.