如何能够动态的控制文件名呢?例如我想按照日期作为输出的文件名,获取当前日期并转换为字符串,怎样才能将这个字符串作为输出文件的文件名呢?谢谢! 
我是一个新手,有点急用,前辈帮帮忙,给出完整的程序
谢谢谢谢!!!

解决方案 »

  1.   

    CString strFileName = "2005-1-1.txt";HANDLE hFile = CreateFile(strFileName ,
             GENERIC_WRITE, FILE_SHARE_READ,
             NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);   if (hFile == INVALID_HANDLE_VALUE)
          AfxMessageBox(_T("Couldn't create the file!"));
       else
       {
          // Attach a CFile object to the handle we have.
          CFile myFile(hFile);      static const char sz[] = "Hockey is best!";      // write string, without null-terminator
          myFile.Write(sz, lstrlen(sz));      // We can call Close() explicitly, but the destructor would have
          // also closed the file for us. Note that there's no need to
          // call the CloseHandle() on the handle returned by the API because
          // MFC will close it for us.
          myFile.Close();
       }
      

  2.   

    CTime t;
    t = CTime::GetCurrentTime();
    CString str = t.Format("%Y-%m-%d");
    str += ".txt";
    CFile file;
    file.Open(str, CFile::modeWrite | CFile::modeCreate);
    char *c = "abc";
    file.Write(c, 3);
    file.Close();
      

  3.   

    谢谢,lfchen(一条晚起的虫) ,lyl_rabbit(阿牛) 
    真的大感谢谢了