This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: unbuffered input


Phil Edwards wrote:
 > On Tue, May 21, 2002 at 02:52:35PM +0200, David Rasmussen wrote:
 >
 >>I want cin only to read the characters from the stdin file, that I ask
 >>it to.
 >
 >
 > This sentence isn't parsing for me.  Can you give an example, please?
 >
 >
 > Phil
 >

If I do getline(cin,str), I ask only for one line. Normally, if more
than one line is available on the stdin file (keyboard, pipe, whatever),
str will be filles with the first line, but cin's buffer (cin.rdbuf()),
will be filled with some or all of the next characters available on the
file. But I want unbuffered I/O, so that the buffer is never filled. If
I say getline(cin,str), I want every character up until the first '\n',
but no more. None in the buffer.
In other words, there are three levels:

If we have input "david rasmussen\ncopenhagen, denmark\n", well have
this, after getline(cin,str)

         chars in str | chars in cin's buffer | chars still in stdin

1: "david rasmussen"  "copenhagen, denmark"    ""

2: "david rasmussen"  ""                       "copenhagen, denmark"



1: is what normally happens
2: is what I want to happen



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]