Peeking an entire line from an istream

R

Randy

How do you do this? getline() *extracts* the characters. peek()
only reads a character at a time. Sure would be nice to have
a "peekline()".

--RY
 
I

int2str

Randy said:
How do you do this? getline() *extracts* the characters. peek()
only reads a character at a time. Sure would be nice to have
a "peekline()".

What do you need it for?

An alternative approach would be to something like this:

void peekline( ifstream & is, string & s )
{
streampos sp = is.tellg();
getline( is, s );
is.seekg( sp );
}

Cheers,
Andre
 
R

Randy Yates

What do you need it for?

Hi Andre,

Thanks for your response.

I'm creating a set of classes for some functions that require
lots of parameters. A simple, human-readable and -controllable
way to do this is to overload the inserter and extractor
operators to report and control these parameters as
property/value pairs, e.g., "ParameterA=value1".

The idea is to feed a list of property/value pairs to the top-level
class, have his extractor interpret and set the properties that
pertain to it (and ignore those that don't), then pass the entire set
to the child classes, the children to their grandchildren, etc.
(speaking hierarchically and/or inheritance-wise).

So, I need to operate on an istream without wasting the
string (or stream) in it.
An alternative approach would be to something like this:

void peekline( ifstream & is, string & s )
{
streampos sp = is.tellg();
getline( is, s );
is.seekg( sp );
}

Yes, that would seem to work. Thanks for the hint. I'm amazed that
this type of function built into the class.
--
% Randy Yates % "...the answer lies within your soul
%% Fuquay-Varina, NC % 'cause no one knows which side
%%% 919-577-9882 % the coin will fall."
%%%% <[email protected]> % 'Big Wheels', *Out of the Blue*, ELO
http://home.earthlink.net/~yatescr
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top