Unit 'System' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#rtl]

Read

Read from a text file into variable.

Declaration

Source position: system.fpd line 60

procedure Read(

  var F: Text;

  Args: Arguments

);

procedure Read(

  Args: Arguments

);

Description

Read reads one or more values from a file F, and stores the result in V1, V2, etc.; If no file F is specified, then standard input is read. If F is of type Text, then the variables V1, V2 etc. must be of type Char, Integer, Real, String. If F is a typed file, then each of the variables must be of the type specified in the declaration of F. Untyped files are not allowed as an argument.

In earlier versions of FPC, it was also allowed to read Pchar null-terminated strings, but this has been removed, since there is no buffer checking possible.

Errors

If no data is available, empty values are returned (0 for ordinal values, empty strings for string values)

See also

Readln

  

Read from a text file into variable and goto next line.

Blockread

  

Read data from an untyped file into memory.

Write

  

Write variable to a text file or standard output.

Blockwrite

  

Write data from memory to an untyped file.

Example

Program Example50;

{ Program to demonstrate the Read(Ln) function. }

Var S : String;
    C : Char;
    F : File of char;

begin
  Assign (F,'ex50.pp');
  Reset (F);
  C:='A';
  Writeln ('The characters before the first space in ex50.pp are : ');
  While not of) and (C<>' ') do
    Begin
    Read (F,C);
    Write (C);
    end;
 Writeln;
 Close (F);
 Writeln ('Type some words. An empty line ends the program.');
 repeat
   Readln (S);
 until S='';
end.

Documentation generated on: Oct 02 2024