首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

紧急如何老是出错的

2013-09-28 
紧急求救啊,怎么老是出错的#include windows.h#include stdio.h#includesys/timeb.h#includeiostre

紧急求救啊,怎么老是出错的


#include <windows.h>
#include <stdio.h>
#include<sys/timeb.h>
#include<iostream>
using namespace std;
unsigned long get_time()
{
    struct timeb timebuffer;
    ftime(&timebuffer);
    return timebuffer.time*1000 + timebuffer.millitm;
}
int main(){
char* aa;
 _ultoa(get_time(),aa,10);
 cout<<aa<<endl;
}


如上代码,为什么一运行就出错,“0x54acd4cc (msvcr100d.dll) 处有未经处理的异常: 0xC0000005: 写入位置 0xcccccccc 时发生访问冲突”


我的主要目的就是得到当前时间距离1970年1月1日的毫秒数,并存到一个 char* 类型的变量中 C++ 时间
[解决办法]
没有给aa分配内存
[解决办法]
char *ultoa(unsigned long value, char *string, int radix); 
ultoa函数把 value转换成一个以空格结尾的radix进制的字符串,并存储在string中(至多33个字节),不执行上溢出检查。radix指出value的基数,radi 必须在2-36的范围内。

所以你要给它 aa分配空间 
char aa[48] = {0};
或者 char *a = (char *)malloc(48);

热点排行