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);
 
   IO.Put_Line (Item => "Capacity:" & Quotes.Capacity'Img);
   Quotes.Reserve_Capacity (Capacity => 100);
   IO.Put_Line (Item => "Capacity:" & Quotes.Capacity'Img);
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
   --  Lets assume that there are no more than 100 quotes in the file,
   --  so we reserve space for that amount of elements.
   Quotes.Reserve_Capacity (Capacity => 100);
 
   IO.Put_Line (Item => "Capacity:" & Quotes.Capacity'Img);
   IO.Put_Line (Item => "Length:" & Quotes.Length'Img);
 
   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);
 
   IO.Put_Line (Item => "Capacity:" & Quotes.Capacity'Img);
   IO.Put_Line (Item => "Length:" & Quotes.Length'Img);
 
   --  Lets "reclaim" any unused resources.
   Quotes.Reserve_Capacity (Capacity => Quotes.Length);   
 
   IO.Put_Line (Item => "Capacity:" & Quotes.Capacity'Img);
   IO.Put_Line (Item => "Length:" & Quotes.Length'Img);
end Quotes;

Go back


Navigation