更新时间:2023-11-27 22:52:34
我知道年份总是每行第54到58个字符
"I know that the year is always the 54th to 58th character in each line"
因此,请考虑:
int main ()
{
ifstream in("laugavegurinn.txt", ios::in);
ofstream out("laugavegurinn2.txt");
string str;
multimap<int, string> datayear;
while (getline(in,str)) {
int year = stoi(str.substr(54, 4));
datayear.insert(make_pair(year,str)); //use insert function
// multimap don't have [] operator
}
for (auto v : datayear)
out << v.second << "\n";
in.close();
out.close();
}