我无法让下面的脚本返回我的输入值;我已经查找了ARM和John Barnes的书,但都没有用。从理论上讲,它应该是可行的。有人知道为什么吗?我是一个新手,所以巴恩斯的书和手臂对我来说可能太高级了。
with Ada.Text_IO;
use Ada.Text_IO;
procedure ron is
A : Character;
begin
Put_Line ("Hi Ron, how are you?");
A := Character'Value (Get_Line);
Put_Line ("So you feel" &
Character'Image (A));
end ron;
--TERMINAL OUTPUT
--ronhans@amante ~/Desktop $ gnatmake -gnat2012 ron.adb
--gcc-4.8 -c -gnat2012 ron.adb
--gnatbind -x ron.ali
--gnatlink ron.ali
--ronhans@amante ~/Desktop $ ./ron
--Hi Ron, how are you?
--well.
--raised CONSTRAINT_ERROR : bad input for 'Value: "well."
发布于 2017-07-15 08:06:25
如果您查看LRM,您将看到Ada.Text_IO.Get_Line
返回一个String
with Ada.Text_IO;
procedure Ron is
begin
Ada.Text_IO.Put_Line ("Hi Ron, how are you?");
declare
Reply : constant String := Ada.Text_IO.Get_Line;
begin
Ada.Text_IO.Put_Line ("So you feel " & Reply & "?");
end;
end Ron;
发布于 2017-07-15 06:56:28
您的程序的问题在于您试图将一个字符数组放入单个字符中。不使用A : Character
,而是尝试定义如下所示的数组类型
type Character_Array_T (1 .. 10) of Character;
...
A : Character_Array_T;
或使用
with Ada.Strings.Unbounded;
...
A : Ada.Strings.Unbounded.Unbounded_String;
我建议使用无界字符串,这样,如果您打算多次读出一个输入,那么输入就不会局限于某个特定的字符串长度。Ada类型string
要求您指定字符串长度,此长度恰好就是此字符串应包含的字符数。
https://stackoverflow.com/questions/45112970
复制相似问题