Convert unbounded string to integer Ada

允我心安 提交于 2019-12-11 06:08:16

问题


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

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

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

expected type "Standard.String" found private type "Ada.Strings.Unbounded.Unbounded_String"

Is what I want to do possible?


回答1:


You just have to do the intermediate conversion:

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;


来源:https://stackoverflow.com/questions/42565836/convert-unbounded-string-to-integer-ada

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!