|
3驿站币
- #include <iostream>
- #include <string>
- #include <time.h>
- using namespace std;
- int main()
- {
- char d[9] = "20190510";
- struct tm t;
- time_t now;
- time(&now);
- localtime_s(&t, &now);
- char buff[9];
- sprintf_s(buff, "%04u%02u%02u", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday);
- cout << d << '\n';
- cout << buff << '\n';
- if (d == buff)
- {
- cout << "等于了";
- }
- else
- {
- cout << "不等于";
- }
- }
复制代码 |
最佳答案
查看完整内容
d 和 buff 都是普通的数组,没办法直接用 == 判断是否字符串相等,比较的结果只是判断两个地址是否相等,要比较两个 char 类型的字符串是否相等,使用 strcmp 啊
上一篇: 请教个问题,为什么会报错下一篇: 有会lua c++游戏开发的没
|