您的位置:首页 > 编程语言 > C语言/C++

C++primer plus第六版课后编程练习答案5.7

2015-11-26 14:59 260 查看
#include<iostream>
#include<math.h>
#include<string>
//#include <array>
using namespace std;
struct car
{
<span style="white-space:pre">	</span>string carmaker;
<span style="white-space:pre">	</span>int yearmade; 
};
void main()
{
int n;
cout<<"How many cars do you wish to catalog?";
cin>>n;//cin>>会遗留换行符到输入缓存,所以要用cin.get()去掉,不然会被getline()获取
cin.get();
car *cars=new car
;
for(int i=0;i<2;i++)
{
cout<<"Car #"<<i+1<<":\n";
cout<<"Please enter the make:";
getline(cin,cars[i].carmaker);
cout<<"Please enter the year made:";
cin>>cars[i].yearmade;
cin.get();
}
cout<<"Here is your collection"<<endl;
for(i=0;i<2;i++)
cout<<cars[i].yearmade<<" "<<cars[i].carmaker<<endl;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: