我知道如何在 mfc 中获取当前日期和时间。但我想借助日期和时间数据类型对数组进行排序。
我该怎么做?
问候,
卡提克
最佳答案
CTime 有一个“<”运算符,因此您可以使用 std::sort()
void SortTime(CTime vals[], size_t nVals)
{
std::sort(vals, vals+nVals);
}
如果您有一个包含 CTimes 的对象,您可以创建自己的“<”运算符。
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);
}
或更好
void SortStuff(std::vector<MyStuff> vals)
{
std::sort(vals.begin(), vals.end());
}
关于c++ - 如何在mfc中对日期和时间进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5401790/