Differences

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

Link to this comparison view

vectors.last_index [2012/01/23 22:05] (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;
 +   ​Empty ​    : 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 => Quotes.Last_Index'​Img);​
 +   ​IO.Put_Line (Item => Empty.Last_Index'​Img);​
 +end Quotes;
 +</​code>​
 +
 +<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;
 +   ​Empty ​    : 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 => Quotes.Last_Index'​Img);​
 +   ​IO.Put_Line (Item => Empty.Last_Index'​Img);​
 +   
 +   if Empty.Last_Index = No_Index then
 +      IO.Put_Line ("​No_Index"​);​
 +   end if;
 +   
 +   if Empty.Last_Index = Empty.First_Index - 1 then
 +      IO.Put_Line ("​No_Index"​);​
 +   end if;
 +end Quotes;
 +</​code>​
 +
 +[[Ada.Containers.Vectors#​Vectors.Last_Index | Go back]]
  

Navigation