Operator Overloading |
Download |
In and Out Parameters. |
--
-- This reads in a string on a line and skips leading blanks, but it uses
-- a procedure.
--
with Gnat.Io; use Gnat.Io;
procedure ReadRest2 is
procedure ReadStr(Str: out String; Last: out Integer) is
I: Integer; -- Input subscript.
Ch: Character; -- Input character.
begin
-- Read to first non-blank character and put it into the first
-- position of the array.
loop
Get(Ch);
exit when Ch /= ' ';
end loop;
Str(Str'first) := Ch;
-- Read the rest of the line into the part of the array after the
-- first position.
Get_Line(Str(Str'First+1..Str'last), Last);
end ReadStr;
Max: constant := 20; -- Max size of string.
Fred: String(1..Max); -- String.
I: Integer; -- Size of read.
begin
-- Get the string.
ReadStr(Fred, I);
-- Echo the whole string, leading blanks trimmed.
Put_Line(Fred(1..I));
end ReadRest2;
Operator Overloading |
In and Out Parameters. |