如何在Ada中获得向量长度?

时间:2015-03-18 03:51:57

标签: ada

示例源代码http://www.waratuman.com/2010/06/02/vectors_in_ada/

with Ada.Containers.Vectors;
with Ada.Integer_Text_IO;
with Ada.Text_IO;
use Ada.Containers;

procedure Euler3 is

    package Integer_Vectors is new Vectors(Natural, Integer);

    Numbers : Integer_Vectors.Vector;
    Cursor : Integer_Vectors.Cursor;

begin

    -- Get some content
    Integer_Vectors.Append(Numbers, 43);
    Integer_Vectors.Append(Numbers, 44);
    Integer_Vectors.Append(Numbers, 45);

    Cursor := Integer_Vectors.First(Numbers);
    while Integer_Vectors.Has_Element(Cursor) loop
        Ada.Integer_Text_IO.Put(Integer_Vectors.Element(Cursor));
        Ada.Text_IO.New_Line;
        Integer_Vectors.Next(Cursor);
    end loop;

end Euler3;

如何从上面的代码获得Integer_Vectors长度?

1 个答案:

答案 0 :(得分:1)

没关系,发现它

Integer_Vectors.Length(Numbers)

或者,更整洁,

Numbers.Length