Ada, raised CONSTRAINT_ERROR : bad input for 'Value: "well."
Ada, raised CONSTRAINT_ERROR : bad input for 'Value: "well."
我无法将以下脚本获取到 return 我的输入值;我已经查阅了 ARM 和 John Barnes 的书,但无济于事。理论上它应该工作。
有人知道为什么吗?我是新手,所以 Barnes 的书和 ARM 对我来说可能太先进了。
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."
你的程序的问题在于你试图将一个字符数组放入一个字符中。不要使用 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 type string
要求你指定字符串长度,这个长度就是这个字符串应该包含的字符数。
参见 Wiki, unbounded strings and Unbounded string handling 以供参考。
如果您查看 LRM,您会看到 Ada.Text_IO.Get_Line
returns a 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;
我无法将以下脚本获取到 return 我的输入值;我已经查阅了 ARM 和 John Barnes 的书,但无济于事。理论上它应该工作。 有人知道为什么吗?我是新手,所以 Barnes 的书和 ARM 对我来说可能太先进了。
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."
你的程序的问题在于你试图将一个字符数组放入一个字符中。不要使用 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 type string
要求你指定字符串长度,这个长度就是这个字符串应该包含的字符数。
参见 Wiki, unbounded strings and Unbounded string handling 以供参考。
如果您查看 LRM,您会看到 Ada.Text_IO.Get_Line
returns a 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;