From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,479138db2311e415 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newshub.sdsu.edu!elnk-nf2-pas!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread3.news.pas.earthlink.net.POSTED!a6202946!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Newbie Question: using Text_IO.Open() to read from standard input References: <1129164557.586640.154480@g14g2000cwa.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Thu, 13 Oct 2005 05:26:30 GMT NNTP-Posting-Host: 67.3.209.117 X-Complaints-To: abuse@earthlink.net X-Trace: newsread3.news.pas.earthlink.net 1129181190 67.3.209.117 (Wed, 12 Oct 2005 22:26:30 PDT) NNTP-Posting-Date: Wed, 12 Oct 2005 22:26:30 PDT Xref: g2news1.google.com comp.lang.ada:5585 Date: 2005-10-13T05:26:30+00:00 List-Id: 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