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;
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);
 
   --  Output the contents of index no. 9
   SUIO.Put_Line (Item => Quotes.Element (9));
 
   --  Append a new element to the vector 
   Quotes.Append (New_Item => To_Unbounded_String ("Test append"));
 
   --  Output the contents of index no. 10
   SUIO.Put_Line (Item => Quotes.Element (10));
end Quotes;
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;
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);
 
   SUIO.Put_Line (Item => Quotes.Element (9));
 
   --  Append the 3 identical elements to the vector
   Quotes.Append (New_Item => To_Unbounded_String ("Test append"),
                  Count => 3);
   SUIO.Put_Line (Item => Quotes.Element (10));
   SUIO.Put_Line (Item => Quotes.Element (11));
   SUIO.Put_Line (Item => Quotes.Element (12));
end Quotes;
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;
   My_Quotes : Vector;
   Input     : IO.File_Type;
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);
 
   My_Quotes.Append (New_Item => To_Unbounded_String ("My 1st. quote"));
   My_Quotes.Append (New_Item => To_Unbounded_String ("My 2nd. quote"));
   My_Quotes.Append (New_Item => To_Unbounded_String ("My 3rd. quote"));
 
   SUIO.Put_Line (Item => Quotes.Element (9));
   SUIO.Put_Line (Item => My_Quotes.Element (0));
 
   --  Append the My_Quotes vector to the Quotes vector
   Quotes.Append (New_Item => My_Quotes);
   SUIO.Put_Line (Item => Quotes.Element (12));
end Quotes;

Go back


Navigation