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

#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;
}

 

转载于:https://www.cnblogs.com/lynnycy/p/3450355.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值