啊啊哦哦啦啦 2019-04-30 14:32 采纳率: 0%
浏览 552

c++智能指针的使用问题??

我这个编译器只支持auto_ptr,所以我只能用这个。
每次编译器也不说我哪里错了,总是给我弹出这个
图片说明

图片说明

代码

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <memory>

using namespace std;

struct Review{
    string title;
    int rating;
};

bool FillReview(Review * rr);   //输入函数 

int main()
{   
    vector <auto_ptr <Review> > books;
    Review temp;
    while (FillReview(&temp)) books.push_back(auto_ptr <Review>(new Review(temp)));

    return 0; 
}

bool FillReview(Review * rr)    //输入,成功返回true,否则返回false 
{
    cout << "请输入书名(q停止):";
    getline(cin, rr->title);

    if (rr->title == "q") return false;

    cout << "请输入书的评分:";
    if (!(cin >> rr->rating)) return false;

    while (cin.get() != '\n') continue;

    return true;
}
  • 写回答

1条回答 默认 最新

  • J4cks0n 2019-04-30 15:12
    关注

    看到运行卡到红线那里,应该是编译器不支持C++11
    201103L : C++11;
    201402L : C++14;
    199711L : C++03/98;
    考虑更新下gcc;
    还有顺带一提
    books.push_back(auto_ptr (new Review(temp)));
    books.push_back(auto_ptr (new Review(std::move(temp))));
    用转移构造函数会不会好一点

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料