使用asctime_s,可以与解释参数类型c ++的人一起做

Using asctime_s and could do with someone explaining the argument types c++

本文关键字:类型 一起 参数 解释 asctime 使用      更新时间:2023-10-16

我正在尝试为我的程序创建一个时间戳并输出它。目前我在编译时有两个错误:

    错误
  1. 1 错误 C2664:"errno_t asctime_s(字符 *,size_t,常量 tm *)":无法将参数 1 从"tm *"转换为"字符 *"
  2. 2 智能感知:重载函数"asctime_s"的实例与参数列表不匹配 参数类型为:(整数、字符 [256]、TM *)

我正在为此查看的文档是 http://msdn.microsoft.com/en-us/library/b6htak9c.aspx

我有以下代码:

char buffer[256];
time_t rawtime;
tm timeinfo;
errno_t result = localtime_s(&timeinfo, &rawtime);
cout << "Current local time and date: " << asctime_s(256, buffer, &timeinfo) << endl;

然后显示"没有重载函数"asctime_s"的实例与参数列表匹配,参数类型为:(tm *,time_t *)"但是,使用指向timeinfo和rawtime的指针会导致localtime_s进一步错误。

有人可以向我解释一下,因为我并不真正理解文档。

亲切问候

编辑

已将代码更改为

char buffer[256];
time_t rawtime;
tm timeinfo;
errno_t result = localtime_s(&timeinfo, &rawtime);
cout << "Current local time and date: " << asctime_s(buffer, &timeinfo) << endl;

它现在正在运行,但是我收到以下弹出错误消息,任何人都可以建议吗?https://i.stack.imgur.com/8JFby.png

asctime_s的第一个参数应该是一个字符数组;你正在传递一个指向tm的指针,看起来它应该是第二个参数。 第二个错误只是说它找不到与您在调用中传递的类型匹配的asctime_s版本。