Ada-从文本文件中获取字符串并存储在数组中

Ada-从文本文件中获取字符串并存储在数组中,ada,Ada,嗨,我只是想知道如果我循环txt并将其存储在一个组合名称中,如何将数据放入数组中 过程是主要的 类型A_数组是_组合的数组(自然范围); 类型A_复合材料为 记录 名称:无界_字符串; 结束记录; 文件:Ada.Text\u IO.File\u类型; 行计数:整数:=0; 开始 Ada.Text_IO.Open(文件=>File, Mode=>Ada.Text\u IO.In\u文件, Name=>“highscore.txt”); 而不是文件(文件)循环的Ada.Text\u IO.End\u

嗨,我只是想知道如果我循环txt并将其存储在一个组合名称中,如何将数据放入数组中

过程是主要的
类型A_数组是_组合的数组(自然范围);
类型A_复合材料为
记录
名称:无界_字符串;
结束记录;
文件:Ada.Text\u IO.File\u类型;
行计数:整数:=0;
开始
Ada.Text_IO.Open(文件=>File,
Mode=>Ada.Text\u IO.In\u文件,
Name=>“highscore.txt”);
而不是文件(文件)循环的Ada.Text\u IO.End\u
声明
行:字符串:=Ada.Text\u IO.Get\u行(文件);
开始
--我想将行字符串存储到数组中。但我不知道怎么做
结束;
端环;
Ada.Text_IO.Close(文件);
端干管;

好的,这里有一个无约束数组。这是有影响的;在声明或初始化对象(一般意义上,而不是OOP)时,可以看到无约束数组获得其确定长度

作为示例,让我们以字符串(无约束字符数组)为例来了解其工作原理:

-- Create a string of 10 asterisks; the initialization takes those bounds.
A : constant string(1..10):= (others => '*');

-- Create a string of 10 asterisks; but determined by the initialization value.
B : constant string := (1..10 => '*');

-- Another way of declaring a string of 10 asterisks.
C : constant string := ('*','*','*','*','*','*','*','*','*','*');
现在,您可以从函数调用中获得这些边界;这意味着我们可以使用函数调用递归地返回这些值

Function Get_Text return An_Array is
  Package Unbounded renames Ada.Strings.Unbounded;
  -- You'll actually want the Get_Line that takes a file.
  Function Get_Line return Unbounded.Unbounded_String
    renames Unbounded.Text_IO.Get_Line;
begin
  return (1 => (Name => Get_Line)) & Get_Text;
exception
  when End_Error => return ( 1..0 => (Name => Unbounded.Null_Unbounded_String) );
end Get_Text;

这就是使用无约束数组的方法。

好的,这里有一个无约束数组。这是有影响的;在声明或初始化对象(一般意义上,而不是OOP)时,可以看到无约束数组获得其确定长度

作为示例,让我们以字符串(无约束字符数组)为例来了解其工作原理:

-- Create a string of 10 asterisks; the initialization takes those bounds.
A : constant string(1..10):= (others => '*');

-- Create a string of 10 asterisks; but determined by the initialization value.
B : constant string := (1..10 => '*');

-- Another way of declaring a string of 10 asterisks.
C : constant string := ('*','*','*','*','*','*','*','*','*','*');
现在,您可以从函数调用中获得这些边界;这意味着我们可以使用函数调用递归地返回这些值

Function Get_Text return An_Array is
  Package Unbounded renames Ada.Strings.Unbounded;
  -- You'll actually want the Get_Line that takes a file.
  Function Get_Line return Unbounded.Unbounded_String
    renames Unbounded.Text_IO.Get_Line;
begin
  return (1 => (Name => Get_Line)) & Get_Text;
exception
  when End_Error => return ( 1..0 => (Name => Unbounded.Null_Unbounded_String) );
end Get_Text;

因此,这就是使用无约束数组的方法。

请添加示例输入,并解释您确切期望的内容、发生的情况,如果有,请给出错误消息。可能重复的。是否确实要将行存储在数组中?为什么要将它们存储在阵列中?您是否知道数组对象无法更改其范围?您是否尝试编译已发布的源文本?请添加示例输入,并解释您的确切期望,相反会发生什么,如果有,请给出错误消息。可能重复的。是否确实要将行存储在数组中?为什么要将它们存储在阵列中?您是否知道数组对象不能更改其范围?您是否尝试编译发布的源文本?