我这个编译器只支持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;
}
看到运行卡到红线那里,应该是编译器不支持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))));
用转移构造函数会不会好一点