-1

我想在大小为 10X10 的矩阵中的最后一列之后添加一些列。我编写了如下代码:

 for i:=1 to N
      do
    begin
      for j:=1 to N  do
        if j = N then
        begin
         if fileexists('d:\A\'+'img'+inttostr(I)+' '+'0'+'.bmp') then

          Write(f,input^[i]^[j],' ','0')
        end
          else
           Write(f,input^[i]^[j],' ','1');

但是这段代码在其他列之间添加了列。谁能解决这个问题?

4

1 回答 1

3

FileExists我认为您比您预期的要早结束您的测试。

在写入所有固定列之后,此代码将在额外列中写入一些内容。

for i := 1 to N do
begin
  for j := 1 to N do
    Write(f, input^[i]^[j], ' '); 
  // Now it is time for writing the extra column   
  if FileExists('d:\A\' + 'img' + inttostr(i) + ' ' + '0' + '.bmp') then
    WriteLn(f, '0')
  else
    WriteLn(f, '1');
end;

编辑:您只需要为每个索引 i 测试一次文件。更新了代码。

于 2012-07-30T05:17:32.350 回答