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;
A_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);
A_Cursor := Quotes.First;
SUIO.Put_Line (Item => Element (Position => A_Cursor));
-- Move to the next element in the vector using the Next procedure.
Next (Position => A_Cursor);
SUIO.Put_Line (Item => Element (Position => A_Cursor));
-- Move to the next Element in the vector using the Next function.
A_Cursor := Next (Position => A_Cursor);
SUIO.Put_Line (Item => Element (Position => A_Cursor));
-- Move the cursor to the last position, and then call Next again.
-- Note how Next assigns the No_Element value to the cursor.
A_Cursor := Quotes.Last;
SUIO.Put_Line (Item => Element (Position => A_Cursor));
Next (Position => A_Cursor);
if A_Cursor = No_Element then
IO.Put_Line (Item => "No_Element");
end if;
end Quotes;
Go back