使用asctime_s,可以与解释参数类型c ++的人一起做
Using asctime_s and could do with someone explaining the argument types c++
我正在尝试为我的程序创建一个时间戳并输出它。目前我在编译时有两个错误:
- 错误
- 1 错误 C2664:"errno_t asctime_s(字符 *,size_t,常量 tm *)":无法将参数 1 从"tm *"转换为"字符 *"
- 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
版本。
相关文章:
- 将用户定义的类型与 std::vector 和 std::sort 一起使用
- 将 lower_bound/upper_bound 与 2 种不同的类型一起使用
- 不允许将SDL_Cursor与unique_ptr:error不完整类型一起使用
- 将提升属性映射与捆绑类型一起使用
- 将运算符<<与隐式转换的非基本数据类型一起使用时出错
- 将分配的内存与基本数据类型一起使用时,是否需要新放置? std::complex?
- 如何将模运算符与其他数据类型一起使用
- 使用#Define和Typedef与数据类型A一起使用
- 如何编写操作员==与隐式铸造/构造类型一起使用
- 测试 std::p ointer_traits 是否可以与我的类型一起使用
- 是否将invoke_result与void参数类型一起使用
- 将CloudViewer与自定义Pointt类型一起使用
- 将C++模板函数与生成器类型一起使用
- 如何将 std::enable_if 与自推返回类型一起使用
- QMetaType与模板化类型一起工作吗
- 如何将 cin 与未知输入类型一起使用
- 将make_shared与不完整的类型一起使用
- 如何将unordered_set与自定义类型一起使用
- 将"const"与标量类型一起使用的好处?(例如 "const double"或"const int")
- 偏移量可以与从decltype获得的结构类型一起使用吗?