将无界字符串转换为整数Ada [英] Convert unbounded string to integer Ada

查看:88
本文介绍了将无界字符串转换为整数Ada的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单,因为Google让我失望了。如何将无界字符串转换为整数?

My question is rather simple, as Google has let me down. How do I convert an unbounded string to an integer?

如果字符串是有界的,我可以这样做: I:Integer:= Integer' Value( 613);

If the string was bounded, I could do this: I : Integer := Integer'Value("613");

但是,我的字符串是无界的,Ada抛出此错误:

However, my string is unbounded, and Ada throws this error:

预期类型为 Standard.String
找到私有类型为 Ada.Strings.Unbounded.Unbounded_String

我想做些什么吗?

推荐答案

您只需要做中间转换:

I : Integer := Integer'Value (To_String (T));

这是一个完整的测试程序:

Here is a full test program:

with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO; use Ada.Text_IO;

procedure Main is
   T : Unbounded_String := To_Unbounded_String ("613");
   I : Integer := Integer'Value (To_String (T));
begin
   Put_Line (I'Image);
end Main;

这篇关于将无界字符串转换为整数Ada的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆