comp.lang.ada
 help / color / mirror / Atom feed
From: Greg Bond <bond@ee.ubc.ca>
To: Tony Macrellis <tmacrell@awadi.com.au>
Subject: Re: How to convert an integer to a string??
Date: 1996/04/04
Date: 1996-04-04T00:00:00+00:00	[thread overview]
Message-ID: <3164497A.46EF@ee.ubc.ca> (raw)
In-Reply-To: 3163D6E3.645F@awadi.com.au

Tony Macrellis wrote:
> 
> I'm a newbie to ada and need some help!  How do I convert an
> integer to a string?

Good question in light of the inadequate coverage of I/O issues in the 
Barnes Ada 95 text (pet peeve!). I discovered the following short-cut in 
the Ada95 for C/C++ on-line guide at  

http://lglwww.epfl.ch:80/Ada/Ammo/Cplpl2Ada.html

"A simple program below uses Text_IO to print a message to the screen, 
including numerics!
These are achieved by using the types attribute 'Image which gives back 
a String representation of
a value. 

with Ada.Text_IO; use Ada.Text_IO;
procedure Test_IO is
begin
  Put_Line("Test Starts Here >");
  Put_Line("Integer is " & Integer'Image(2));
  Put_Line("Float is   " & Float'Image(2.0));
  Put_Line("Test Ends Here");
end Test_IO;

It is also possible to use one of the generic child packages of Ada. 
Text_IO such as
Ada.Text_IO.Integer_IO which can be instantiated with a particular type 
to provide type safe
textual IO. 

with Ada.Text_IO; 

type My_Integer is new Integer;

package My_Integer_IO is new Ada.Text_IO.Integer_IO(My_Integer);
use My_Integer_IO;



--
* Greg Bond                         * Dept. of Electrical Eng.  
* email: bond@ee.ubc.ca             * Univ. of British Columbia      
* voice: (604) 822 0899             * 2356 Main Mall                 
* fax:   (604) 822 5949             * Vancouver, BC              
* web: http://www.ee.ubc.ca/~bond   * Canada, V6T 1Z4




      reply	other threads:[~1996-04-04  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-04  0:00 How to convert an integer to a string?? Tony Macrellis
1996-04-04  0:00 ` Greg Bond [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox