with Ada.Text_IO;
with Ada.Text_IO.Unbounded_IO;
with Ada.Strings.Unbounded;      use Ada.Strings.Unbounded;
with Ada.Containers.Vectors;     use Ada.Containers;
 
procedure Quotes is
   package IO renames Ada.Text_IO;
   package SUIO renames Ada.Text_IO.Unbounded_IO;
   package Quote_Container is new Vectors (Natural, Unbounded_String);
   use Quote_Container;
   Quotes    : Vector;
   Input     : IO.File_Type;
 
   procedure Add_42 (Element : in out Unbounded_String) is
   begin
      Element := Element & To_Unbounded_String (" 42");
   end Add_42;
   Q_Cursor  : Cursor;
begin
   IO.Open (File => Input,
            Mode => IO.In_File,
            Name => "quotes.txt");
   while not IO.End_Of_File (File => Input) loop
      Quotes.Append (New_Item => SUIO.Get_Line (File => Input));
   end loop;
   IO.Close (Input);
 
   --  Update the first index
   Quotes.Update_Element (Index   => 0,
                          Process => Add_42'Access);
   SUIO.Put_Line (Item => Quotes.Element (Index => 0));
 
   --  Point the cursor at the index 7 of the vector
   Q_Cursor := Quotes.To_Cursor (Index => 7);
   Quotes.Update_Element (Position => Q_Cursor,
                          Process  => Add_42'Access);
   SUIO.Put_Line (Item => Quotes.Element (Index => 7));
end Quotes;

Go back


Navigation