下面这段代码,每次执行到fread的时候就出错,错在那里?
FILE *fp;
long size = 0;
    char read;
    CString str; if (fopen("c:\\text.txt","rb")!=NULL)
{
    while(fread(&read,sizeof(read),1,fp)) 
{   str+=read;
size++;
}
}

解决方案 »

  1.   

    FILE *stream;
       char list[30];
    if( (stream = fopen( "fread.out", "r+t" )) != NULL )
       {
          /* Attempt to read in 25 characters */
          numread = fread( list, sizeof( char ), 25, stream );
          printf( "Number of items read = %d\n", numread );
          printf( "Contents of buffer = %.25s\n", list );
          fclose( stream );
       }
       else
          printf( "File could not be opened\n" );
      

  2.   

    if (fp=fopen("c:\\text.txt","rb")!=NULL)
      

  3.   

    It's really a basic question :) take care all the variables u defined,and where they r used
      

  4.   

    FILE *fp;
    long size = 0;
        char read;
        CString str;
        fp=fopen("c:\\text.txt","rb");
    if (fp!=NULL)
    {
        while(fread(&read,sizeof(read),1,fp)) 
    {   str+=read;
    size++;
    }
    }
      

  5.   

    CFile _fileopen;
    CFileException ex;
        long size = 0;
        char read;
        CString str; if (!_fileopen.Open("c:\\text.txt",
                                 CFile::modeRead |
                                 CFile::typebinary,
                                 &ex))
             { char error[1024];
               ex.GetErrorMessage(szError, 1024); 
              }
              else
    {
        while(_filelopen.Read(&read,sizeof(read)) 
    {   str+=read;
    size++;
    }
    }