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.

live demo


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -