//exercise.cpp
#include<iostream>
#include<string>
using namespace std;
struct car
{
string make;
int year;
};
int main()
{
int n;
cout << "How many cars do you wish to catalog? ";
cin>>n;
cin.get();
car *Car = new car [n];
for (int i = 0; i < n; ++i)
{
cout << "Car #"<<i+1<<":"<< endl;
cout << "Please enter the make: " << (Car+i)->make << endl;
cout << "Please enter the year made: " << (Car + i)->year << endl;
}
delete [] Car;
cout << "Here is your collection:" << endl;
for (int i = 0; i < n; ++i)
{
cout << (Car + i)->year << " " << (Car + i)->make;
cout << endl;
}
cin.get();
return 0;
}
为什么程序在输入2之后,就会直接跳到程序结尾?
#include<iostream>
#include<string>
using namespace std;
struct car
{
string make;
int year;
};
int main()
{
int n;
cout << "How many cars do you wish to catalog? ";
cin>>n;
cin.get();
car *Car = new car [n];
for (int i = 0; i < n; ++i)
{
cout << "Car #"<<i+1<<":"<< endl;
cout << "Please enter the make: " << (Car+i)->make << endl;
cout << "Please enter the year made: " << (Car + i)->year << endl;
}
delete [] Car;
cout << "Here is your collection:" << endl;
for (int i = 0; i < n; ++i)
{
cout << (Car + i)->year << " " << (Car + i)->make;
cout << endl;
}
cin.get();
return 0;
}
为什么程序在输入2之后,就会直接跳到程序结尾?