CTime m_time;
m_time=CTime::GetCurrentTime();
CString strtime=m_time.Format("%x");
CString Filepath=strtime+".bmp";
char pFilePath[MAX_PATH];
int FilePathLength = Filepath.GetLength();     // 获得文件名长度,CFile不能用CString,只能用string做参数,要做转换
for(int m=0; m < FilePathLength ; m++)
{
pFilePath[m] = Filepath.GetAt(m);     // CString -> string

}
pFilePath[m] = '\0';     // 文件名结束
//CFile mFile(_T("user.bmp "), CFile::modeWrite|CFile::modeCreate); 
CFile mFile(pFilePath, CFile::modeWrite|CFile::modeCreate); 
编译运行都能通过,但操作起来就会弹出错,希望大家帮忙看下,感谢

解决方案 »

  1.   


    CTime m_time;
    m_time=CTime::GetCurrentTime();
    CString strtime=m_time.Format("%x");
    strtime.Replace('/','-');
    CString Filepath= _T("D:\\") + strtime+".bmp"; CFile mFile(Filepath, CFile::modeWrite|CFile::modeCreate);  D盘成功创建06-26-11.bmp文件
      

  2.   

    感谢啊,如果路径是D:\\(当前日期)\\....
    我又改了下
    CTime m_time;
    m_time=CTime::GetCurrentTime();
    CString strtime=m_time.Format("%X");
    CString strtime1=m_time.Format("%x");
    strtime.Replace(':','-');
    strtime1.Replace('/','0');
    CString Filepath= _T("D:\\") +strtime1+"\\"+ strtime+".bmp";
    这回也是错误,请问怎么改啊,麻烦你了:)
      

  3.   


    CTime m_time;
    m_time=CTime::GetCurrentTime();
    CString strtime=m_time.Format("%X");
    CString strtime1=m_time.Format("%x");
    strtime.Replace(':','-');
    strtime1.Replace('/','0');
    CString Filepath= _T("D:\\") +strtime1+"\\"+ strtime+".bmp";

    CreateDirectory(_T("D:\\") +strtime1, 0);
    CFile mFile(Filepath, CFile::modeWrite|CFile::modeCreate);  
      

  4.   

    for(int m=0; m < FilePathLength ; m++)
    {
    pFilePath[m] = Filepath.GetAt(m); // CString -> string}
    pFilePath[m] = '\0'; // 文件名结束
    =========
    CString本身就提供了转换,根本就不用这么麻烦,直接写成
    LPTSTR pFilePath=Filepath.GetBuffer(0);就行了。
      

  5.   

    注意把 获得的文件路径改成  d:\\test\\1.txt 这种形式,不要将得到的pFilePath 直接用就好
      

  6.   

    我找到了MakeSureDirectoryPathExists这个函数,也蛮好的
    感谢楼上各位的帮助