gpt4 book ai didi

type-conversion - 字符到字符串的转换 Ada

转载 作者:行者123 更新时间:2023-12-02 06:50:16 24 4
gpt4 key购买 nike

我正在尝试遍历字符并使用 Put_Line() 打印它们函数,但它需要字符串参数,而不是字符。是否可以使用 'Image() 将 char 转换为 String ,就像我可以用 Integer 做的那样?我的代码:

with Ada.Text_IO;
use Ada.Text_IO;

procedure Main is

begin
for I in 'A' .. 'Z' loop
Put_Line(I);
end loop;
end Main;

最佳答案

您的问题不仅是字符转换,而且您还需要通知编译器您将使用哪种字符,是的,您可以使用 Image 属性来获取字符的字符串表示。

with Ada.Text_IO;
use Ada.Text_IO;

procedure Main is

begin
for I in Character range 'A' .. 'Z' loop
Put_Line(I'Image);
end loop;
end Main;

此代码将起作用。

关于type-conversion - 字符到字符串的转换 Ada,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46789647/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com