如果不告知,会使ada程序的输出缩进什么?

我目前正在从learn.adacore.com开始进行Ada教程,现在是第二个示例:读取并输出一个整数。由于复制粘贴适用于不想学习语法的人,因此我手动输入了大部分代码(其中一些代码是由gnat-gps生成的,但是我现在使用的是vim)。

我编译并运行了该程序,令人惊讶的是,输出的第二行大约缩进了一个制表符。为什么?

代码如下:

With Ada.Text_IO;
Use Ada.Text_IO;
With Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure Main is
    N : Integer;
begin
   --  Insert code here.
    Put("Enter an integer value: ");
    Get(N);
    if N>0 then
        Put (N);
        Put_Line(" is a positive number");
    end if;
end Main;

(如何突出显示语法?)

以下是输出示例(第一个输入):

Enter an integer value: 1
          1 is a positive number
CL1314520CLCL 回答:如果不告知,会使ada程序的输出缩进什么?

Ada.Integer_Text_IO中的Put过程使用默认字段宽度填充空格。 该过程的规范在Ada Language Reference Manual中定义为:

procedure Put(Item  : in Num;
              Width : in Field := Default_Width;
              Base  : in Number_Base := Default_Base);

为Width和Base参数指定默认值。您对Put的调用仅提供了形式参数Item的值。要消除左填充,只需指定所需的宽度即可。我建议您像

一样对呼叫使用Ada命名符号
Put(Item => N,Width => 1);
本文链接:https://www.f2er.com/3090203.html

大家都在问