'localtime': This function or variable may be unsafe. Consider using localtime_s instead....

我用Visual Studio的时候报错了,因为我要获取时间,报错是这样,你看看差不多是这样吧?

严重性 代码  说明  项目  文件  行   禁止显示状态
错误  C4996   'localtime': This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. MemoPad E:\ProgramThomas\Coding-Notes\Project\CPP\NoteBook\MemoPad\MemoPad\MemoPad.cpp  53  

当时的代码是这样:

void memo_add(string strdata)
{
    ofstream fout("E:/ProgramThomas/Coding-Notes/Project/CPP/NoteBook/MemoPad/MemoPad/Table_Data/data.md", ios::app);
    fout << "|" << count << "|";
    //TODO:time-UTC-tomorrow
    time_t now_time = time(NULL);
    tm* t_tm = localtime(&now_time);
    fout << t_tm << "|";
    fout << strdata << "|";
    //TODO:is-ok?-tomorrow
    //
    count++;
}

其实这个代码的localtime没有问题,就是VS的问题,在程序预处理位置加入这一行代码就行了

#pragma warning(disable:4996)

你可能感兴趣的:('localtime': This function or variable may be unsafe. Consider using localtime_s instead....)