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

编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第5章编程练习6

2013-11-29 21:49 387 查看
#include <iostream>
#include <string>
using namespace std;
struct car
{
string pro;
int year;
};
int main()
{
int num;
cout<<"How many cars do you wish to catalog? ";
(cin>>num).get();//注意将输入后的回车键转换成的换行符读取并丢弃
car *newcar=new car[num];
for(int i=0;i<num;i++)
{
cout<<"Car #"<<i+1<<":"<<endl;
cout<<"Please enter the make: ";
getline(cin,newcar[i].pro);
cout<<"Please enter the year made: ";
(cin>>newcar[i].year).get();//注意将输入后的回车键转换成的换行符读取并丢弃
cout<<"Here is your collection:"<<endl;
for(int j=0;j<num;j++)
cout<<newcar[j].year<<" "<<newcar[j].pro<<endl;
delete [] newcar;//删除开辟的动态空间
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐