Ada:put()具有自定义类型

Ada:put()具有自定义类型,ada,Ada,我正在寻找将Put()函数与我创建的自定义类型一起使用的方法。我怎么能这样做 with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; procedure main is type count is range -2..2 ; begin Put(counter); end main; 这就是我得到的: Builder results C:\Users\*********

我正在寻找将Put()函数与我创建的自定义类型一起使用的方法。我怎么能这样做

with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;

procedure main is
   type count is range -2..2 ;
begin
      Put(counter);
end main;
这就是我得到的:

Builder results
    C:\Users\***********\Desktop\ada project\src\main.adb
        26:11 expected type "Standard.Integer"
        26:7 no candidate interpretations match the actuals:
        26:7 possible missing instantiation of Text_IO.Integer_IO

您缺少实例,
Counter
,并且没有子程序
Put
接受类型为
Count
的参数。一些选择:

  • 选项1-使用
    图像
    属性
  • 选项2-转换为类型
    整数
  • 选项3-定义子类型而不是类型
  • 选项4-实例化通用包
    Ada.Text\u IO.Integer\u IO
with Ada.Text_IO;

procedure Main is
   type Count is range -2 .. 2;   
   Counter : Count := 1;   
begin
   Ada.Text_IO.Put (Counter'Image);   -- Counter'Image returns a String
   -- or 
   Ada.Text_IO.Put (Count'Image (Counter));
end Main;
with Ada.Integer_Text_IO;

procedure Main is
   type Count is range -2 .. 2;   
   Counter : Count := 1;    
begin
   Ada.Integer_Text_IO.Put (Integer (Counter));  
end Main;
with Ada.Integer_Text_IO;

procedure Main is
   subtype Count is Integer range -2 .. 2;   
   Counter : Count := 1;  
begin
   Ada.Integer_Text_IO.Put (Counter);  
end Main;
with Ada.Text_IO;

procedure Main is

   type Count is range -2 .. 2;   
   Counter : Count := 1; 

   package Count_Text_IO is
      new Ada.Text_IO.Integer_IO (Count);   

begin
   Count_Text_IO.Put (Counter);   
end Main;