CString TimeToString()
{
CTime   nowTime = CTime::GetCurrentTime();
int  iYear = nowTime.GetYear();
int  iMonth = nowTime.GetMonth();
int  iDay = nowTime.GetDay();
int   iHour = nowTime.GetHour();
int   iMinute = nowTime.GetMinute();
int   iSecond = nowTime.GetSecond();
char  strTemp[20];
char   strTemp_1[20];
char  strTime[100];
itoa(iYear, strTemp, 10);
strcpy(strTime, " ");
strcat(strTime, strTemp);
strcat(strTime, "/");
if (iMonth < 10)
{
strcpy(strTemp, "0");
itoa(iMonth, strTemp_1, 10);
strcat(strTemp, strTemp_1);
}
else
{
itoa(iMonth, strTemp, 10);
}
strcat(strTime, strTemp);
strcat(strTime, "/");
if (iDay < 10)
{
strcpy(strTemp, "0");
itoa(iDay, strTemp_1, 10);
strcat(strTemp, strTemp_1);
}
else
{
itoa(iDay, strTemp, 10);
}
strcat(strTime, strTemp);
strcat(strTime, "--");
if (iHour < 10)
{
strcpy(strTemp, "0");
itoa(iHour, strTemp_1, 10);
strcat(strTemp, strTemp_1);
}
else
{
itoa(iHour, strTemp, 10);
}
strcat(strTime, strTemp);
strcat(strTime, ":");
if (iMinute < 10)
{
strcpy(strTemp, "0");
itoa(iMinute, strTemp_1, 10);
strcat(strTemp, strTemp_1);
}
else
{
itoa(iMinute, strTemp, 10);
}
strcat(strTime, strTemp);
strcat(strTime, ":");
if (iSecond < 10)
{
strcpy(strTemp, "0");
itoa(iSecond, strTemp_1, 10);
strcat(strTemp, strTemp_1);
}
else
{
itoa(iSecond, strTemp, 10);
}
strcat(strTime, strTemp);
CString sReturn;
sReturn.Format("%s", strTime);
return sReturn;}类似这样冗长的代码在程序中还有很多。。唉,因为每一段代码都有可能引发崩溃,所以又不能跳过不看。

解决方案 »

  1.   

    直接return CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
    中间的- :可以用你想要的替换掉。为什么采用这么麻烦的手段?
      

  2.   

    建议楼主重写该函数,采用CString的Format方法实现。
      

  3.   

    我也很有帮他重新改写的冲动,但是如果找不到出问题的地方,即使重写后没有问题了,也不安心呀。
    这是个视频监控的程序,有远程端和本地端,我被告知崩溃是发生在网络报警频繁出现的时候。
    楼上几位仁兄说得很好,调试、设断点,我也很同意,但是我这里并不具备运行环境(触发网络报警)。
    所以只能看代码。。>_<
      

  4.   

    直接调试定位到崩溃地点
    如果程序崩溃时有提示内存地址
    也可以修改编译选项,生成map文件,根据崩溃地址定位
      

  5.   

    其实上面那段还好啦,这个程序最绝的就是,有一个读写注册表的函数,从开始的位置向后翻页,感觉代码行象浩瀚的海洋,一眼望不到边。
    我尝试按住右边的滚动条来浏览它,但是拉到一半发现整个代码区都变成了白色,咦~难道这个家伙加了那么多空白行??我再把水平滚动条往右拉原来由于层层缩进,代码已经超出整个屏幕了。。我的VC6字体是CourierNew 9号,屏幕分辨率1280x1024。
      

  6.   


    周思博怎么说的来着?任何想要量化管理脑力工作者的工作量的行为都将是徒劳的.
    假如一个公司用代码数以及修改问题数来衡量程序员的工作的话,那么结果将是程序员
    先写出一大堆烂代码,然后再慢慢修改其中的bug
      

  7.   

    算了,直接用一楼的替换了吧,~~~要看程序是在那个函数里崩溃的可以用drwtsn32.exe工具
      

  8.   

    为什么不直接使用CString?而是使用了一些数组和内存的操作函数呢?
      

  9.   


    上面的代码我已经用AStyle格式化过了。
      

  10.   

    记住崩溃地址, 查map文件定位出错代码行。