“localtime”被声明为否决的,为什么?怎么改?

干饭人之路 2009-10-21 02:58:06
有一个关于时间小程序,编译连接时提示:
正在编译...
1>cgtest.cpp
1>.\cgtest.cpp(9) : warning C4996: “localtime”被声明为否决的
1> C:\Program Files\Microsoft Visual Studio 8\VC\include\time.inl(114) : 参见“localtime”的声明
1> 消息:“This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.”
程序如下:

#include "stdafx.h"
#include <ctime>
using namespace std;
int main()
{
cout<<"hello world!!!"<<endl;
time_t t;
time(&t);
tm *pt=localtime(&t);
printf("%s",pt->tm_year);
}

stdafx.h的内容如下:
#include <stdio.h>
#include <iostream>
#include <tchar.h>

请问什么原因?
...全文
381 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
浪漫不属意 2012-08-30
  • 打赏
  • 举报
回复
_localtime32的参数会变啊
浪漫不属意 2012-08-30
  • 打赏
  • 举报
回复
localtime_s的返回值不是tm*啊,怎么办啊?我也没解决这问题
spiritzero 2009-12-20
  • 打赏
  • 举报
回复
用Localtime_s(tm* , const time_t*)函数
真相重于对错 2009-10-21
  • 打赏
  • 举报
回复
_localtime32

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧