文件读写例子有错误:
program Project2;
{$APPTYPE CONSOLE}
uses
SysUtils;
const
FileName1='c:\test1.txt';
FileName2='c:\test2.txt';
var
F1,F2:TextFile;
S:string;
begin
AssignFile(F1,FileName1);
AssignFile(F2,FileName2);
Rewrite(F2);
Writeln(F2,'Hello');
while not eof(F1)do
begin
Readln(F1,S);
Writeln(F2,S);
end;
CloseFile(F1);
CloseFile(F2);
end.
while not eof(F1)do是不是死循环啊?
------解决方法--------------------------------------------------------
uses
SysUtils;
const
FileName1='c:\test1.txt';
FileName2='c:\test2.txt';
var
F1,F2:TextFile;
S:string;
begin
AssignFile(F1,FileName1);
AssignFile(F2,FileName2);
Rewrite(F2);
Writeln(F2,'Hello');
Reset(F1)
while not eof(F1)do
begin
Readln(F1,S);
Writeln(F2,S);
end;
CloseFile(F1);
CloseFile(F2);
end.