我现在是这个样子:
char* bin[10000];
mNewFile.Read (bin,mNewFile.GetLength ());难道要给bin数组设为很大很大?不可能吧:(

解决方案 »

  1.   

    ...
    CFile myFile;
    CFileException e;
    char * pFileName = "D:\\...\\test.txt";
    myFile.Open(pFileName,CFile::modeRead,&e);
    //得到文件大小
    DWORD dwsize = myFile.GetLength();
    char * buffer;
    myFile.Read(buffer,dwsize);
    ...
    不知道是不是这个意思?
      

  2.   

    use GetLength() to get the size of the file, allocate a memory, then call SeekToBegin(), then use Read():
    virtual UINT Read( void* lpBuf, UINT nCount );
      

  3.   

    char* bin[10000];//错误,定义10000个指针。
    mNewFile.Read (bin,mNewFile.GetLength ());
    这样:
    LPSTR buf;
    CFile pf;pf.Open(...);
    buf=new char[pf.Getlength()];
    pf.Read(buf,pf.GetLength());
    pf.Close();//do somethingdelete buf;
      

  4.   

    使用 CArray,可以在使用前设置缓冲的长度
      

  5.   


    CFile file;
    file.Open();
    DWORD dwLength = file.GetLength();
    BYTE* pData = new BYTE[dwLength];
    ASSERT(pData);
    DWORD dwRead = file.ReadHuge(pData,dwLength);
    ASSERT(dwRead==dwLength); file.Close(); 
    这种办法适合于内容不是很大的文件,如果文件内容很大,应该采用分段读取的办法.这样,对读出来的数据的操作,不会因为内存太大而影响了速度.
      

  6.   

    kimryo(code-fragment)的方法怎么写入后都成了“铪铪铪”了:(
      

  7.   

    do not use ReadHuge(), according to MSDN
    ReadHuge() Can read more than 64K of (unbuffered) data from a file at the current file position. Obsolete in 32-bit programming. Use Read()
      

  8.   

    beegee(提头游于市--别怕,是我自己的猪头)的方法出错
      

  9.   

    2 karma:
    void*也出错:(
      

  10.   

    beegee:谢谢,我再试一下:)
      

  11.   

    对不起各位,pabulum,欢迎您,您的专家分:20、可用分:1334、参与分:305 参与分太少,不能多加分了