我目前正在做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;(如何突出显示语法?)
以下是输出的示例(第一个1是输入):
Enter an integer value: 1
1 is a positive number发布于 2019-11-17 00:24:34
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的调用只为形参项目提供了一个值。要消除左填充,只需指定所需的宽度。我建议您使用Ada命名表示法进行调用,如下所示
Put(Item => N, Width => 1);https://stackoverflow.com/questions/58890911
复制相似问题