FILE *fp;
CString ftmp=strPath+"\\"+strFileName;   LPTSTR lpsz = new TCHAR[ftmp.GetLength()+1];
 strcpy(lpsz,ftmp);
 if((fp=fopen(lpsz,"r"))!=NULL)
 {  
   AfxMessageBox("读取"+strPath+"\\"+strFileName+"文件成功!");
    fclose(fp);
}问题出在fopen()lpsz这个参数上,我如果用"C:\\aa\\a.text"这个字串代替就是正常.请问大家我这个传参有什么不对得吗?

解决方案 »

  1.   

    跟踪看看lpsz是啥东西是C:\\aa\\a.text吗??
      

  2.   

    你使用了宽字符了,但是fopen不支持,你可以使用_wfopen试一试
      

  3.   

    有可能是lpsz不对...
    有可能是你的字符串中少了\f10单步调试一下
      

  4.   

    lpsz是什么文件,隐藏的,系统的fopen好像打不开。
      

  5.   

    FILE *fp;
    CString ftmp=strPath+"\\"+strFileName;
             AfxMessageBox(ftmp);//先看看文件名及路径正确与否 if((fp=fopen(ftmp,"r"))!=NULL)
    {  
       AfxMessageBox("读取"+strPath+"\\"+strFileName+"文件成功!");
        fclose(fp);
      

  6.   

    你调试看看 lpsz 的值是什么?是正确的路径吗?
    这么简单的问题调试一看就知道了。改为下面的试试:int nLength = ftmp.GetLength()+1;
    char *lpsz = new char[nLength];
    memset(lpsz, 0x00, nLength*sizeof(char));
    strcpy(lpsz,ftmp);
      

  7.   

    lpsz里面是C:\aa\a.text
    这样不行吗?
      

  8.   

    strcpy(lpsz,ftmp);
    ->
    strcpy(lpsz, ftmp.GetBuffer(0)) ;
    TRACE0(lpsz);
      

  9.   

     strFileName=finder.GetFileName();
    FILE *fp;
    CString ftmp=strPath+"\\"+strFileName; char *lpsz = new CHAR[ftmp.GetLength()+1];
    strcpy(lpsz,ftmp);
    if((fp=fopen(lpsz,"r"))!=NULL)
    {  
    AfxMessageBox("读取"+strPath+"\\"+strFileName+"文件成功!");
    fclose(fp);
    }这样也不行,我都快吐了,怎么搞的,跟踪发现,lpsz为C:\aa\a.text