Ada - 在此上下文中需要子类型标记
Ada - Subtype mark required in this context
我正在尝试制作一个简单的循环程序,但在第 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;
在成员资格测试中,两个值必须属于同一类型。在你的情况下,
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
我正在尝试制作一个简单的循环程序,但在第 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;
在成员资格测试中,两个值必须属于同一类型。在你的情况下,
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