C++获取系统时间按照年-月-日格式化输出的运行错误,
代码如下:time_tnowtime;nowtime=time(NULL);structtm*local;local=NULL;local=localtime(&nowt...
代码如下:
time_t nowtime;
nowtime=time(NULL);
struct tm *local;
local=NULL;
local=localtime(&nowtime);
char *buffer=new char[12];
strftime(buffer,12,"%F",local);
cout<<buffer<<endl;
运行后报错,求解! 展开
time_t nowtime;
nowtime=time(NULL);
struct tm *local;
local=NULL;
local=localtime(&nowtime);
char *buffer=new char[12];
strftime(buffer,12,"%F",local);
cout<<buffer<<endl;
运行后报错,求解! 展开
1个回答
2012-01-15
展开全部
下面的程序在VC6上验证ok,你试试:
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
time_t nowtime;
nowtime=time(NULL);
struct tm *local;
local=NULL;
local=localtime(&nowtime);
char *buffer=new char[12];
strftime(buffer,128,"%c",local);
cout<<buffer<<endl;
return 0;
}
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
time_t nowtime;
nowtime=time(NULL);
struct tm *local;
local=NULL;
local=localtime(&nowtime);
char *buffer=new char[12];
strftime(buffer,128,"%c",local);
cout<<buffer<<endl;
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询