一个按钮,一个editbox,第一步:点击按钮时在editbox中显示当前时间,(已经实现)
CTime time; 
time=CTime::GetCurrentTime(); 
    m_strShow+=time.Format("%Y年%m月%d日  %X \r\n");
UpdateData(FALSE); 
第二步:点击按钮,自动生成一个TXT文档,中包含点击按钮所获得的信息,应该怎么做啊?谢谢大侠们~~~~

解决方案 »

  1.   

    fopen("xxx.txt","wb");
    fwrite(xxx);会自动把xxx写入到xxx.txt里
      

  2.   

    UpdateData(TRUE);
    CStdioFile file(L"e:\\ss.txt");
    file.WriteString(m_strShow);
    file.Close();
      

  3.   

       CTime t_now1 = CTime::GetCurrentTime();
        CString temp_time1 = t_now1.Format("%Y-%m-%d %H:%M:%S");
        CString filename = ".\\" + t_now1.Format("%m%d") + ".txt";//文件路径
        CFile   file;
        if(filename.IsEmpty())
        {
            return;
        }
        file.Open(filename,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate);//打开文件没有则创建
        file.SeekToEnd();
        file.Write("\n" + temp_time1 + " " + str, strlen("\n" + temp_time1 + " " + str));//写入数据
        file.Write("\r\n", 2);//换行
        file.Close();
      

  4.   


    CFile file;
    file.Open("001.txt", CFile::ModeReadWrite);
    file.Write(...);
    file.Close();--------------------------------------------------------CFile类的成员数据成员 m_hFile 常包含操作系统文件句柄  构造函数 CFile 从一个路径或文件句柄构造一个CFile对象  
    Abort 不管任何警告和错误,关闭一个文件  
    Duplicate 构造一个基于该文件的副本  
    Open 带错误检验选项,安全打开一个文件  
    Close 关闭文件,删除对象  输入/输出 Read 从文件的当前位置读数据  
    ReadHuge 可从文件的当前位置读取大于64K数据,在32位编程中废弃了,见Read  
    Write 将文件数据写入当前文件位置  
    WriteHuge 可将文件的大于64K数据写到当前文件位置,在32位编程中废弃了,见Write  
    Flush 溢去未被写入的任何数据  定位 Seek 定位于当前文件指针  
    SeekToBegin 定位当前文件指针到文件开头  
    SeekToEnd 定位当前文件指针到文件尾  
    GetLength 获取文件长度  
    SetLength 改变文件长度  封锁 LockRange 在文件中封锁一定范围内的字节  
    UnlockRange 解锁一定范围内的字节  状态 GetPosition 获取当前文件指针  
    GetStatus 获取打开文件的状态  
    GetFileName 获取被选文件的文件名  
    GetFileTitle 获取被选文件的标题  
    GetFilePath 获取被选文件的完整路径  
    SetFilePath 设置被选文件的完整路径  静态 Rename 改名指定文件(静态函数)  
    Remove 删除指定文件(静态函数)  
    GetStatus 获取指定文件的状态(静态,虚函数)  
    SetStatus 设置指定文件的状态(静态,虚函数)  
      

  5.   

    file.Write("\n" + temp_time1 + " " + str, strlen("\n" + temp_time1 + " " + str));//写入数据 
    哥哥 这句话报错啊 啥意思能解释下嘛?谢谢了
      

  6.   

    FILE *fp;
    if((fp=fopen(lpstrName,"w+"))==NULL)
    {
        AfxMessageBox("cannot open file\n");
    }
    else
    {  
        fputs(m_strShow,fp);
        fputs("\n",fp);
    }
    fclose(fp);
      

  7.   

    FILE *fp;
    if((fp=fopen(lpstrName,"w+"))==NULL)
    {
        AfxMessageBox("cannot open file\n");
    }
    else
    {  
        fputs(m_strShow,fp);
        fputs("\n",fp);
    }
    fclose(fp);
      

  8.   

    FILE *fp;
    if((fp=fopen(lpstrName,"w+"))==NULL)
    {
        AfxMessageBox("cannot open file\n");
    }
    else
    {  
        fputs(m_strShow,fp);
        fputs("\n",fp);
    }
    fclose(fp);