即将一个二进制文件与一个文本文件合并,二进制文件在前面,文本文件在后面?

解决方案 »

  1.   

    用CreateFile()  ReadFile() WriteFile() 应该没问题的。我一直这么用
      

  2.   

    可以
    刚好我以前做过
    给你贴下代码//
    //将 m_MailAddr的内容写入到m_Path文件的尾部(长度为30,如果m_MailAddr的地址不足30,则添加空格至于30,方便以后读出)
    //
    void CSetupDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    CFileDialog mFileDlg(TRUE, NULL,NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ALLOWMULTISELECT,"All Files (*.*)|*.*| |", AfxGetMainWnd()); 
    if (mFileDlg.DoModal()==IDOK)
    {
    m_Path=mFileDlg.GetPathName();
    UpdateData(FALSE);
    }
    }
    void CSetupDlg::OnButton2() 
    {
    // TODO: Add your control notification handler code here

    UpdateData(TRUE);
    if ((m_Path.GetLength()==0)||(m_MailAddr.GetLength()==0))
    {
    ::MessageBox(NULL,"目标文件和E-Mail地址不能为空!","警告",MB_ICONINFORMATION);
    return;
    }
    CFile MyFile(m_Path,CFile::modeReadWrite|CFile::modeNoTruncate); 
    MyFile.SeekToEnd();
    if (m_MailAddr.GetLength()>30)
    {
    ::MessageBox(NULL,"E-Mail地址太长,请重新输入!","Information",MB_ICONINFORMATION);
    return;
    }
    while(m_MailAddr.GetLength()<30)
    {
    m_MailAddr=m_MailAddr+" ";
    }
    MyFile.Write(m_MailAddr,m_MailAddr.GetLength());
    MyFile.Close();
    ::MessageBox(NULL,"恭喜,操作成功!","Information",MB_ICONINFORMATION);
    }
      

  3.   

    //
    //下面是将尾部的文本读出来的代码,原来的代码找不到了,顺手写的,可能有点问题,你
    //自己再修改一下
    // CFile f1(_pgmptr,CFile::modeRead|CFile::modeNoTruncate);
    f1.Seek((f1.GetLength-30),CFile::begin);
    CFile f2("c:\\test.txt",CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate);
    char buff[30];
    ZeroMemory(buff,30); f1.Read(buff,30);
    f2.Write(buff,30); f1.Close();
    f2.Close();