在下面的程序中,我想创建一个nameBook,它是一个字符串数组,这样我就可以存储5个名字。您可以在下面看到我是如何做到的。当我尝试编译时,我得到下面显示的错误。这是什么问题?
with ada.integer_text_io; use ada.integer_text_io;
with ada.text_io; use ada.text_io;
with ada.strings.unbounded; use ada.strings.unbounded;
procedure nameStorer is
nameBook : array(1..5) of unbounded_string;
begin
nameBook := ("tom","mary","harry","william","kate");
end nameStorer;
编译错误:
nameStorer.adb:10:16: expected private type "Ada.Strings.Unbounded.Unbounded_String"
nameStorer.adb:10:16: found a string type
nameStorer.adb:10:24: expected private type "Ada.Strings.Unbounded.Unbounded_String"
nameStorer.adb:10:24: found a string type
nameStorer.adb:10:33: expected private type "Ada.Strings.Unbounded.Unbounded_String"
nameStorer.adb:10:33: found a string type
nameStorer.adb:10:40: expected private type "Ada.Strings.Unbounded.Unbounded_String"
nameStorer.adb:10:40: found a string type
nameStorer.adb:10:47: expected private type "Ada.Strings.Unbounded.Unbounded_String"
nameStorer.adb:10:47: found a string type
答案 0 :(得分:4)
"tom","mary","harry","william","kate"
是String
类型的文字(确切地说是Standard.String
)。您的nameBook
是Unbounded_String
(Ada.Strings.Unbounded.Unbounded_String
)类型的数组。您需要将字符串文字转换为Unbounded_Strings。
查看Ada.Strings.Unbounded
(RM A.4.5/9)
To_Unbounded_String