Article View: net.lang.c++
Article #290Streams: line-by-line mode and flushing.
From: Stephen J. Muir
Date: Sun, 17 Aug 1986 23:16
Date: Sun, 17 Aug 1986 23:16
29 lines
1588 bytes
1588 bytes
I wanted to write a routine which would read one file and write another, a line
at a time. I was rather annoyed to find that the "get" routine for "istream"s
left the '\n' in the stream instead of skipping past it. Surely, if I want to
read a line at a time, I'm not interested in the line terminator (which I
*know* the value of because I have, implicitly or otherwise, specified it).
Anyway, I wrote a quick test program and found, to my annoyance, that each
output line appears the line after I expected it to. Here is what I wrote:
# include <stream.h>
char buf [82];
main ()
{ while (cin.get (buf, 80))
{ char c;
cin.get (c);
cout << buf << "\n";
}
}
In desperation, I put a "cout.flush();" after line 9, which didn't help.
C++ Version 1.1, BSD 4.2, VAX-11/750.
--
EMAIL: stephen@comp.lancs.ac.uk | Post: University of Lancaster,
UUCP: ...!mcvax!ukc!dcl-cs!stephen | Department of Computing,
Phone: +44 524 65201 Ext. 4120 | Bailrigg, Lancaster, UK.
Project:Alvey ECLIPSE Distribution | LA1 4YR
Technical Details
Message-ID:
<374@comp.lancs.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!ukc!dcl-cs!stephenShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!mcvax!ukc!dcl-cs!stephen From: stephen@comp.lancs.ac.uk (Stephen J. Muir) Newsgroups: net.lang.c++ Subject: Streams: line-by-line mode and flushing. Message-ID: <374@comp.lancs.ac.uk> Date: Sun, 17-Aug-86 19:16:47 EDT Article-I.D.: comp.374 Posted: Sun Aug 17 19:16:47 1986 Date-Received: Wed, 20-Aug-86 23:30:24 EDT Reply-To: stephen@comp.lancs.ac.uk (Stephen J. Muir) Organization: Department of Computing at Lancaster University, UK. Lines: 29