quiettttt 2022-09-20 15:28 采纳率: 97.9%
浏览 22
已结题

这一行的get()有什么用?为什么不能删去?



void newit_1()
{
    typedef struct {
        string name;
        double diameter;
        double weight;
    }Pizza;
    Pizza *pizza = new Pizza ;//指针

    cout << "How many big do you want?"<< endl;
    (cin >> pizza[0].diameter).get() ;
    cout << "Please enter the name of the company!"<<endl;
    getline(cin , pizza[0].name);
    cout << "weight?" << endl;
    cin >> pizza[0].weight;

    cout << "The name of the Pizza Company: " <<  pizza[0].name << endl;
    cout << "The diameter of the Pizza Company: " << pizza[0].diameter<< endl;
    cout << "The weight of the Pizza Company: " << pizza[0].weight << endl;

    delete pizza;

}
    (cin >> pizza[0].diameter).get() ;

这一行的get()有什么用,最好具体一点。为什么不能删去?

  • 写回答

1条回答 默认 最新

  • 快乐鹦鹉 2022-09-20 15:44
    关注

    get()应该是用来接收掉输入一个浮点数以后的换行符的。否则下面的getline可能接收这个换行符,导致没有正确接收输入的名称信息

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月28日
  • 已采纳回答 9月20日
  • 创建了问题 9月20日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度