2017-02-20 44 views
0

不好意思問這個問題,但Ada在輸入和輸出系統上真的很嚴格,所以我無法弄清楚如何從輸入和輸出系統獲取輸入用戶並將其放入數組中。Ada如何從用戶獲得輸入的整數列表並將其放入數組

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

procedure Main is 
type MY_ARRAY is array(1..9) of INTEGER; 
    Data  : MY_ARRAY; 

begin 
    Put("Please input the series of numbers"); 
    Get_Line(Data); 
end Main; 

我知道這是完全錯誤的,但我研究無處不在,我找不到人如何獲得輸入到一個數組LOL。感謝你的幫助。

+0

另請考慮[* Ada *的命令行參數](http://stackoverflow.com/q/14491899/230513)。 – trashgod

+0

該鏈接看起來像是處理字符串tho。 Ada是否有任何獲取數組輸入的方法?感謝幫助的人。 –

+0

可能的任務是將單個數字放入數組的組件中?或者,爲此,找到一種從字符串中提取單個數字的方法? – B98

回答

0

我認爲只使用Ada.Text_IO包可以更簡單,以便您可以將每個數字讀取爲一個字符串,然後使用for循環將其逐個存儲爲整數,並使用for循環和Integer'Value(將字符串轉換爲整數)逐個存儲。

with Ada.Text_IO; 
use Ada.Text_IO; 

procedure Main is 
    type MY_ARRAY is array(1..9) of Integer; 
    Data : MY_ARRAY; 

begin 
    Put_Line("Please input the series of numbers"); 

    for I in 1..MY_ARRAY'Length loop 
     Data(I) := Integer'Value(Get_Line); 
    end loop; 
end Main; 
相關問題