COleDateTime sysTime,sysData;
sysTime=COleDateTime::GetCurrentTime(); //获得系统当前时间
sysData=COleDateTime::GetCurrentTime(); //获得系统当前时间
CString sTime,sData;
sTime=sysTime.Format(VAR_TIMEVALUEONLY); //时间
sData=sysData.Format(VAR_DATEVALUEONLY); //日期strFileName=sData+"_"+sTime+".wav"; //以日期和时间作为文件名
FILE *file1=NULL;
if((file1=fopen(strFileName,"wb"))==NULL)
{
AfxMessageBox("文件打开失败!");
}
提示出错:文件打开失败!
错误原因:sTime=sysTime.Format(VAR_TIMEVALUEONLY)得到的时间含有":",属于特殊字符,不能做文件名。
改正方法:用CTime类中方法获得系统当前时间,不含":"特殊字符。如下所示:
CTime CurrentTime=CTime::GetCurrentTime();
strFileName = CurrentTime.Format( "%Y%m%d%H%M%S" )+".wav";
接下来便可成功创建wav格式的文件。