我正在尝试创建一个简单的循环程序但是在第18行得到错误,在此上下文中需要子类型标记,但是在运行其他程序时我没有收到此错误?
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;
with Ada.Strings.Unbounded;
use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_IO;
use Ada.Text_IO.Unbounded_IO;
procedure main is
input : Unbounded_String;
begin
while input not in "!Close" loop --Line 18
Get_Line(input);
end loop;
end main;
答案 0 :(得分:3)
在成员资格测试中,两个值必须属于同一类型。在你的情况下,
input
是Unbounded_String
,而"!Close"
是字符串文字。
您要么必须将其中一个转换为另一个,要么只使用Ada.Strings.Unbounded
中定义的等于运算符
(而且,既然您已经完成了use Ada.Strings.Unbounded
,那么您可以看到所有替代方案):
while input not in To_Unbounded_String("!Close") loop --Line 18
或
while To_String(input) not in "!Close" loop --Line 18
或
while input /= "!Close" loop --Line 18