comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: Ada vs C++ for numeric IO (integers)
Date: 1996/07/22
Date: 1996-07-22T00:00:00+00:00	[thread overview]
Message-ID: <dewar.838093086@schonberg> (raw)
In-Reply-To: 31F42BF0.6B62@mich.com


Tom Zagotta said:

None of the languages I've ever used have provided "bullet-proof" I/O
functions that get user input; I have always written them myself.  An example
would be a function with the following signature:

  int ReadInteger (const char* Prompt, int Min, int Max)
  {
    // your code here
  }

This function might write out the prompt, read a number from the user, make sure
it's in range, and return the integer when a valid number is typed.



I don't see how that is different from what you would get in Ada from:

  type Input_Integer is range Min .. Max;
  package My_Input is new Ada.Text_IO.Integer_IO (Input_Integer);
  ...
  Put_Line (Prompt);
  My_Input.Get (My_Input_Integer); -- My_Input_Integer is type Input_Integer

then if you want to trap invalid input, catch the exception Data_Error.





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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-22  0:00 Ada vs C++ for numeric IO (integers) Nasser Abbasi
1996-07-22  0:00 ` Tom Zagotta
1996-07-22  0:00   ` Robert Dewar [this message]
1996-07-23  0:00   ` Nasser Abbasi
1996-07-24  0:00 ` Keith Thompson
replies disabled

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