comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam@spam.com>
Subject: Re: Newbie Question: using Text_IO.Open() to read from standard input
Date: Thu, 13 Oct 2005 05:26:30 GMT
Date: 2005-10-13T05:26:30+00:00	[thread overview]
Message-ID: <aem3f.2136$y14.566@newsread3.news.pas.earthlink.net> (raw)
In-Reply-To: <dN2dnRto6cDDItDeRVn-sQ@comcast.com>

tmoran@acm.org wrote:

>   Standard Input is already Open when your program starts, so you
> don't need to open it.
>    ARM A.10(4):  "For all Get and Put procedures that operate on text
> files, and for many other subprograms, there are forms with and without a
> file parameter.  ...  If no file is specified, a default input file or a
> default output file is used."  That's simplest, but you might want instead
> to use things from ARM 10.3 "Default Input, Output, and Error Files".

To clarify a little further, you shouldn't open or close standard input. The Get 
and Get_Line procedures that don't take a file parameter read from 
Current_Input. Current_Input is Standard_Input by default. (There's also a 
Current_Output for Put and Put_Line that default to Standard_Output.)

These procedures read from Current_Input rather than Standard_Input to allow a 
program to read from a file if one if provided and from Standard_Input if not:

if Argument_Count > 0 then
    Ada.Text_IO.Open (File => File, Name => Argument (1), ...);
    Ada.Text_IO.Set_Input (File => File);
end if;

loop
    Get_Line (Item => Line, Last => Last);
    -- Use Line
end loop;

if Argument_Count > 0 then
    Ada.Text_IO.Close (File => File);
end if;

-- 
Jeff Carter
"Many times we're given rhymes that are quite unsingable."
Monty Python and the Holy Grail
57



  parent reply	other threads:[~2005-10-13  5:26 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-13  0:49 Newbie Question: using Text_IO.Open() to read from standard input pamela.lum
2005-10-13  1:30 ` Anh Vo
2005-10-13  1:48   ` pamela.lum
2005-10-13  1:56     ` Anh Vo
2005-10-13 16:14     ` Martin Krischik
2005-10-13  1:58 ` tmoran
2005-10-13  2:02   ` pamela.lum
2005-10-13  2:19     ` Anh Vo
2005-10-13  5:26   ` Jeffrey R. Carter [this message]
2005-10-13  6:53     ` tmoran
2005-10-13  3:15 ` Steve
replies disabled

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