Differences

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

Link to this comparison view

vectors.first [2012/01/23 22:06] (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;
 +   ​Q_Cursor ​ : Cursor;
 +   ​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);
 +   
 +   ​-- ​ This is bad. If we change the Index_Type from Natural to Positive,
 +   ​-- ​ 0 would no longer be the first position in the vector.
 +   ​Q_Cursor := Quotes.To_Cursor (Index => 0);
 +   ​SUIO.Put_Line (Item => Element (Position => Q_Cursor));
 +   
 +   ​-- ​ This is good. We always get the first position, no matter what 
 +   ​-- ​ Index_Type we're using.
 +   ​Q_Cursor := Quotes.First;​
 +   ​SUIO.Put_Line (Item => Element (Position => Q_Cursor));
 +end Quotes;
 +</​code>​
 +
 +[[Ada.Containers.Vectors#​Vectors.First | Go back]]
  

Navigation