comp.lang.ada
 help / color / mirror / Atom feed
From: "Anders Wirzenius" <anders.wirzenius@pp.qnet.fi>
Subject: Re: Command_Line question
Date: Tue, 11 Dec 2001 06:57:32 GMT
Date: 2001-12-11T06:57:32+00:00	[thread overview]
Message-ID: <w7iR7.26$jy2.2127@read2.inet.fi> (raw)
In-Reply-To: 3C152834.F1B1850F@avercom.net


Tucker Taft wrote in message <3C152834.F1B1850F@avercom.net>...
>"Peter I. Hansen" wrote:
>>
>> Hello
>>
>> I'm new to Ada95, and I'm trying to write a program which needs to read
>> arguments from the command line. I found out that the Command_Line
>> package is the way to go, but something i don't get. for example if I
>> have this code :
>>
>> WITH Ada.Text_IO;
>> WITH Ada.Command_Line;
>> WITH Ada.Integer_Text_IO;
>>
>> PROCEDURE Test IS
>>
>> Num : Natural ;
>> NumLength : Natural ;
>>
>> BEGIN -- Test
>>    Ada.Integer_text_IO.Get( From => Ada.Command_Line.Argument(Number =>
1),
>>                             Item => Num,
>>                             Last => NumLenght);
>
>Generally, it is easier to use "Integer'Value(blah)" than
"Integer_Text_IO.Get(...)".
>Integer_Text_IO gives you more control, but Integer'Value is usually
adequate.

FWIW
One of the "more control" things is that Integer_Text_IO.Get(..) will
swallow a command line like "Test 3a" or "Test 3." where the Get stops
reading at the character "a" or "."
The Integer'Value(..) will raise an exception.

Neither of them accepts "Test a3".

As a newbe to Ada95 myself I have been through the same process as Peter. I
want to recommend (as has been done by several persons on cla earlier)
studying the generous possibilities that the attributes offer, see
http://www.quickreferences.yucom.be/QRC/Ada%20Reference%20Card.pdf

Anders Wirzenius







  reply	other threads:[~2001-12-11  6:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-10 20:29 Command_Line question Peter I. Hansen
2001-12-10 21:25 ` Tucker Taft
2001-12-11  6:57   ` Anders Wirzenius [this message]
2001-12-11 12:26   ` Peter I. Hansen
2001-12-10 21:53 ` Mark Lundquist
2001-12-11 13:03 ` Marc A. Criley
replies disabled

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