zoukankan      html  css  js  c++  java
  • 编程菜鸟的日记-初学尝试编程-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;
    }

  • 相关阅读:
    学习进度笔记14
    学习进度笔记13
    学习进度笔记12
    学习进度笔记11
    学习进度笔记10
    学习进度笔记9
    学习进度笔记8
    学习进度笔记7
    学习进度笔记6
    微信客户端兼容性
  • 原文地址:https://www.cnblogs.com/lynnycy/p/3450355.html
Copyright © 2011-2022 走看看