Read a file line by line: Difference between revisions

No edit summary
Line 317:
}</lang>
The File is managed by reference count, and it gets closed when it gets out of scope or it changes. The 'line' is a char[] (with newline), so if you need a string you have to idup it.
 
 
=={{header|Delphi}}==
<lang Delphi>
procedure ReadFileByLine;
var
TextFile: text;
TextLine: String;
begin
Assign(TextFile, 'c:\test.txt');
Reset(TextFile);
while not Eof(TextFile) do
Readln(TextFile, TextLine);
CloseFile(TextFile);
end;
</lang>
The example file '''"c:\test.txt"''' is assigned to the text file variable '''"TextFile"''' is opened and any line is read in a loop into the string variable '''"TextLine"'''.
 
=={{header|Forth}}==
16

edits