这样可以:
CString filename=...;//你的文件名
//创建文件对象,打开文件
CFile theFile;
CFileException fileException;
//文件打开时出错
if (!theFile.Open (filename,CFile::modeRead,
&fileException))
{
//输出出错消息
TRACE("不能打开文件%s.error=%u\n",
filename,fileException.m_cause ); //文件打不开,提示并禁止用户进入下一步
AfxMessageBox("文件打开出错!");
}
//安全打开文件
else
{
//读64个字节
                           char string[63]={64*0};
theFile.Seek(lg,CFile::begin);
theFile.Read (&string,64);
CString p=string;
m_titleName=string;
         }

解决方案 »

  1.   

    我要的是例如二进制文件是 "FF D8 FF",变成string就是 "FF D8 FF"。 
      

  2.   

    这个你自己想把~!good luck!
      

  3.   

    void CBinEditView::ShowBinfile(CString filename)
    {
    CFile binfile;
    CString str,tmpstr,totalstr;
    long length;
    unsigned int buflen;
    DWORD haslen=0;
    totalstr.Empty();
    str.Empty();
    tmpstr.Empty();
    if(!binfile.Open(filename,CFile::modeRead,NULL))
    MessageBox("不能打开文件!",NULL,MB_ICONWARNING);
    else{
    length=binfile.GetLength();
    BYTE* lpbuf=new BYTE[length];
    binfile.Read(lpbuf,length);
    while(length>0)
    {
    if(length>2048)buflen=2048;else buflen=length;
        for(unsigned int i=1;i<buflen+1;i++)
    {
       tmpstr.Format("0x%02x,",lpbuf[i+haslen-1]);
       str+=tmpstr;
       if(i%16==0)str+=0x0a;
    }
     str.MakeUpper();
     totalstr+=str;
     str.Empty();
    length-=2048;
    haslen+=2048;
    }
    binfile.Close();
    }
    }