I know how to get the current date and time in mfc.but I want to sort the array with the help of date and time datatype.
How can I do this?
Regards,
karthik
CTime has a "<" operator, so you can use std::sort()
void SortTime(CTime vals[], size_t nVals)
{
std::sort(vals, vals+nVals);
}
If you have an object containing CTimes, you can create your own "<" operator.
struct MyStuff
{
std::string sName;
int nNumber;
CTime time;
};
bool operator < (const MyStuff &lhs, const MyStuff &rhs)
{
return lhs.time < rhs.time;
}
void SortStuff(MyStuff vals[], size_t nVals)
{
std::sort(vals, vals+nVals);
}
or better
void SortStuff(std::vector<MyStuff> vals)
{
std::sort(vals.begin(), vals.end());
}
C
orC++
(or something else)? I believe the answer is different to the different languages. – pmgC++
, I've removed thec
tag. – pmg