Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 什么';我的函数以字符串形式给出当前日期,这是错误的_C++ - Fatal编程技术网

C++ 什么';我的函数以字符串形式给出当前日期,这是错误的

C++ 什么';我的函数以字符串形式给出当前日期,这是错误的,c++,C++,当我比较两个字符串“当前日期”和“过去日期”时,它显示当前日期不大于过去日期 我试着比较str和str2,比较结果是正确的 string str="21/05/2019"; string str2="7/06/2019"; string c=GetCurrentDate(); if(c>str) { cout<<"true"; } string str=“21/05/2019”; 字符串str2=“7/06/2019”;

当我比较两个字符串“当前日期”和“过去日期”时,它显示当前日期不大于过去日期

我试着比较str和str2,比较结果是正确的

string str="21/05/2019";
    string str2="7/06/2019";
    string c=GetCurrentDate();
    if(c>str)
    {
        cout<<"true";
    }
string str=“21/05/2019”;
字符串str2=“7/06/2019”;
字符串c=GetCurrentDate();
如果(c>str)
{

CUT< P>比较字符串与日期/时间类型的不同。最好使用一些内置类型来表示日期,例如STD::Tim::Timo或类似的东西。C++给了你操纵这些类型的工具,所以你不需要重新发明轮子。 虽然我认为std::time并不“用户友好”,但我建议看一下下面的参考资料


最好使用内置类型来表示时间

但是为了回答你的问题,因为你在比较字符串,它可能是,这不是你想要的

"7/06/2019" < "8/09/2019" // even though the month is higher


但是,如果可以的话,一定要使用为时间/日期而设计的内置类型来代替字符串。

c>str1
无法正确使用日期格式。如果使用年/月/日,则可以。您可以尝试ISO 8601格式,该格式专为处理字符串比较而设计。
"7/06/2019" < "8/09/2019" // even though the month is higher

"2019/mm/dd" > "2018/mm/dd";
"2019/06/dd" > "2019/05/dd" ;
"2019/06/25" > "2019/06/19";