C++ VS2013 unsafe

来源:互联网 发布:淘宝如何修改类目 编辑:程序博客网 时间:2024/06/14 20:02

//#define _CRT_SECURE_NO_WARNINGS


#include <iostream>
#include <ctime>

using namespace std;

int main()
{
// 基于当前系统的当前日期/时间
time_t now = time(0);

// 把 now 转换为字符串形式
char* dt = ctime(&now);


cout << "本地日期和时间:" << dt << endl;

// 把 now 转换为 tm 结构
tm *gmtm = gmtime(&now);
dt = asctime(gmtm);
cout << "UTC 日期和时间:" << dt << endl;
}


如果没有第一句,就会报错:

Error 1 error C4996: 'ctime': This function or variable may be unsafe. Consider using ctime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.c:\users\summer\desktop\exercise\consoleapplication2\consoleapplication2\source1.cpp161 ConsoleApplication2

原创粉丝点击