在一行上打印多个项目

合并 _IO 包的实例,使用正确的数据类型。

with Ada.Text_IO;   use Ada.Text_IO;

procedure Print_Inventory is
    type Fruit is (Banana, Orange, Pear);
    subtype Count is Integer range -1_000_000 .. 1_000_000;

    package Fruit_IO is new Enumeration_IO (Fruit);
    package Count_IO is new Integer_IO (Count);

    Inventory : constant array (Fruit) of Count :=
      (Banana => 27_420,
       Orange => 140_600,
       Pear   => -10_000);

begin
    Fruit_IO.Default_Width := 12;

    for F in Inventory'Range loop
        Fruit_IO.Put (F);
        Put          (" | ");
        Count_IO.Put (Inventory (F));
        New_Line;
    end loop;
end Print_Inventory;

结果

BANANA       |    27420
ORANGE       |   140600
PEAR         |   -10000