程序写了一半,请教各位达人给予指正!****************************************
    CFileDialog dlg(TRUE, "dat","*.dat");
if(dlg.DoModal()==IDOK)
{
    CStdioFile file;
VERIFY(file.Open(dlg.GetFileName(),CFile::modeRead)|CFile::typeBinary);
         
           UINT nBytesRead = file.Read(a,2000);
           }
  a为一全局变量  short a[1000];编译无错误,但个人感觉读文件的方法还是有问题的。
请各位达人给指点指点

解决方案 »

  1.   

    UINT nBytesRead  = 0;
         UINT nAllRead = 0;
          do
          {
             nAllRead += nBytesRead;
             nBytesRead = file.Read(a + nAllRead,2000 * sizeof(short) - nAllRead);
          }
          while (nBytesRead > 0);
      

  2.   


      在读数组a时候是否要要做如下:**********************
    for(int i=999;i>0;i++)
    {
       a[i]=a[i-1];
    }
    然后在画图?
      

  3.   

    the return value of Read may be less than the count to read if the end of file was reached, so you must see what the value of nBytesRead is.and you must allocate memory enough to store the data from read the file,so short a[1000] array must be allocated large enough.
      

  4.   


      how do you do, phiger!
      I finnally find I just read to  short a[158],when i>158,array element is not right,but I really need large array.
      what should I do, please help me!    楼上的,你是对的,文件中的数组我只能读到158个数, 在后面的就出错了.
      请问, 该怎么做!
      

  5.   

    //打开文件
    HANDLE h=CreateFile(dlg.GetFileName,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
    //文件大小
    DWORD nSize=GetFileSize(h);
    if(nSize>2000) nSize=2000;//最多只读2000个字节
    DWORD s;
    BOOL lR=ReadFile(h,a,nSize,&s,NULL);
    CloseHandle(h);
    //s为返回读的字节数
    if(lR){//成功}else{//不成功}