- というお題が出たとする
- 戻る・進む・クリア・仕様変更に対応したい
- シンプルにvectorを使うのがいいだろう
- 今回確かめたかったのは、構造体を定義したとして、実際の変数を波括弧で作れるかどうか
- 作れました。シンプルな書き方を知っておくのは良いこと
#include<bits/stdc++.h>
using namespace std;
struct History{
int v;
string url;
string title;
bool operator<(const History &another) const{
return v < another.v;
}
};
int main(){
vector<History> H;
H.push_back({2,"aaa","bbb"});
H.push_back({1,"ccc","ddd"});
H.push_back({4,"eee","fff"});
H.push_back({3,"ggg","hhh"});
sort(H.begin(), H.end());
for(auto h : H){
cout << h.v << ' ' << h.url << ' ' << h.title << endl;
}
return 0;
}
Output
1 ccc ddd
2 aaa bbb
3 ggg hhh
4 eee fff