我需要从一个txt文件中读取数据,real型的,共有  50万(有可能变化)行 * 6列var
  num: array of array of real;  //用来存贮数据  n,m:longinteger;                      
  
  s:string;           
  f:textfile;beginn:=0;  //用来判断c:\text.txt 有多少行,实际是 1234567行*6 列
assignfile(f,'c:\test.txt');
reset(f);while not eof(f) do
begin
readln(f,s);
n:=n+1;     
end  
closefile(f);
SetLength(num,n,m);assignfile(f,'c:\test.txt');
reset(f);while not eof(f) do
begin
read(f,a[i,1],a[i,2],a[i,3],a[i,4],a[i,5],a[i,6]);
n:=n+1;     
end
closefile(f);可是提示出错:out of memory想这种情况,怎么处理

解决方案 »

  1.   

    你这一句,i从哪儿来,a又从哪儿来
    read(f,a[i,1],a[i,2],a[i,3],a[i,4],a[i,5],a[i,6]);诸多的错误,给你改了一下var
      num: array of array of real;  //用来存贮数据  n,m:longint;  s:string;
      f:textfile;beginn:=0;  //用来判断c:\text.txt 有多少行,实际是 1234567行*6 列
    assignfile(f,'c:\test.txt');
    reset(f);while not eof(f) do
    begin
    readln(f,s);
    n:=n+1;
    end;
    closefile(f);
    //因为是6列,应该再加个对m赋值的语句
    m:=6;
    SetLength(num,n,m);assignfile(f,'c:\test.txt');
    reset(f); 
    n:=0;
    while not eof(f) do
    begin 
    read(f,num[n,0],num[n,1],num[n,2],num[n,3],num[n,4],num[n,5]);
    n:=n+1;
    end;
    closefile(f);
    end;
      

  2.   

    50万数据×6列×6个字节=1800万字节约等于18mb,按现在内存算,最小都是128mb的,所以完全没问题
      

  3.   

    project project1.exe raised exception class eaccessviolation with message 'access violation at address 0045B01B in module 'project1.exe' write of address 00000000'.
      

  4.   


    我用 matlab 产生的clear
    clcx=30
    y=sin(x)for theta=1:1000000
    fig=fopen('e:\test.txt','a+');
    fprintf(fig,'%6.4f  %6.4f  %6.4f  %6.4f  %6.4f  %6.4f\n',y,y,y,y,y,y);
    fclose(fig);
    end
      

  5.   

    你这样再试试
    procedure TForm1.Button1Click(Sender: TObject);
    var
      num: array of array of real;  //用来存贮数据
      n,nn,m:longint;
      s:string;
      f:textfile;
    begin
      nn:=0;  //用来判断c:\text.txt 有多少行,实际是 1234567行*6 列
      assignfile(f,'c:\test.txt');
      reset(f);
      while not eof(f) do
      begin
        readln(f,s);
        nn:=nn+1;
      end;
      closefile(f);
      //因为是6列,应该再加个对m赋值的语句
      m:=6;
      SetLength(num,nn,m);
      assignfile(f,'c:\test.txt');
      reset(f);
      n:=0;
      repeat
        read(f,num[n,0],num[n,1],num[n,2],num[n,3],num[n,4],num[n,5]);
        n:=n+1;
      until eof(f)or(n<=nn-1);
      closefile(f);
    end;
      

  6.   


    多谢,ok可以为什么用 while 不行呢?
      

  7.   

    我在最后面加上 showmessage(floattostr(num[999,5]));显示的是 0好像不对阿
      

  8.   

    因为readln是一行一行读取的,而read是顺序读取的,当一行数据读完后,还在读该行后面的数据,可是后面已经空了,所以读出来的就是0了
      

  9.   

    这样再试试
    procedure TForm1.Button1Click(Sender: TObject);
    var
      num: array of array of real;  //用来存贮数据
      n,nn,m:longint;
      s:string;
      f:textfile;
      ss:TStringlist;
      j:integer;
    begin
      nn:=0;  //用来判断c:\text.txt 有多少行,实际是 1234567行*6 列
      assignfile(f,'c:\test.txt');
      reset(f);
      while not eof(f) do
      begin
        readln(f,s);
        nn:=nn+1;
      end;
      closefile(f);
      //showmessage(inttostr(nn));
      //因为是6列,应该再加个对m赋值的语句
      m:=6;
      SetLength(num,nn,m);
      assignfile(f,'c:\test.txt');
      reset(f);
      n:=0;
      while not eof(f) do
      begin
        readln(f,s);
        ss:=TStringlist.Create;
        ss.Delimiter:=' ';
        ss.DelimitedText:=s;
        for j:=0 to ss.Count-1 do
          num[n,j]:=strtofloat(ss[j]);
        ss.Free;
        n:=n+1;
      end;
      closefile(f);
      showmessage(floattostr(num[1,0]));
    end;
      

  10.   

    for n := 0 to pred(high(num)) do
        begin
        s:=floattostr(num[n,0])+'  '+floattostr(num[n,1])+'  '+floattostr(num[n,2])+'  '
        +floattostr(num[n,3])+'  '+floattostr(num[n,4])+'  '+floattostr(num[n,5]);
        memo1.Lines.Add(s);
        end;
    测试成功,非常感谢