时间格式要有明确规定就能比较。
例如 HH:MM:SS
一位数前面要补0。 例如 string a="16:04:15"; string b="08:06:55";
这就可以用 > < 了。
#include
#include
using namespace std;
main(){
string a="16:04:15";
string b="08:06:55";
if (a>b) cout << "a>b " << a << endl;
else cout << "a<=b" << endl;
}
如果涉及到年月日时分秒,最好用 time.h 里的 time_t 的时间作比较。
time_t 的单位是 从某日 (可能是 1970年1月1日)起算的秒数,无符号整型。
不知道你们的问题有没有这么复杂。
string可以直接用大于号小于号跟等号
函数嘛strcmp()