c++ - Order dates from a vector -
i read multiple dates file , put every date in vector of struct this:
struct value { string code; string date; string name; };
(the format of date “yyyy-mm-dd hh:mm:ss
")
now want order dates of vector.
any suggestion?
you can use std::sort()
algorithm on vector
:
vector<value> v; ... std::sort (v.begin(), v.end(), [](value&a, value&b)->bool { return a.date<b.date; });
fortunately, date format using alphabetical order corresponds chronological order. if not case, you'd have add date conversion.
Comments
Post a Comment