Differences

This shows you the differences between two versions of the page.

Link to this comparison view

vectors.element [2012/01/23 21:12] (current)
thomaslocke created
Line 1: Line 1:
 +<code ada>
 +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;​
 +   ​Q_Cursor ​ : Cursor; ​ --  Declare the 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);
 +   
 +   ​-- ​ Output first index 0 and then index 7
 +   ​SUIO.Put_Line (Item => Quotes.Element (Index => 0));
 +   ​SUIO.Put_Line (Item => Quotes.Element (Index => 7));
 +   
 +   ​-- ​ Point the cursor at the first index of the vector
 +   ​Q_Cursor := Quotes.To_Cursor (Index => Quotes.First_Index);​
 +   ​SUIO.Put_Line (Item => Element (Position => Q_Cursor));
 + 
 +   ​-- ​ Point the cursor at index 7 of the vector
 +   ​Q_Cursor := Quotes.To_Cursor (Index => 7);
 +   ​SUIO.Put_Line (Item => Element (Position => Q_Cursor));
 +end Quotes;
 +</​code>​
 +
 +[[Ada.Containers.Vectors#​Vectors.Element | Go back]]
  

Navigation