Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Peeking an entire line from an istream

Reply
Thread Tools

Peeking an entire line from an istream

 
 
Randy
Guest
Posts: n/a
 
      01-14-2006
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

 
Reply With Quote
 
 
 
 
int2str@gmail.com
Guest
Posts: n/a
 
      01-14-2006

Randy wrote:
> 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

 
Reply With Quote
 
 
 
 
Randy Yates
Guest
Posts: n/a
 
      01-14-2006
"(E-Mail Removed)" <(E-Mail Removed)> writes:

> Randy wrote:
>> 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?


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."
%%%% <(E-Mail Removed)> % 'Big Wheels', *Out of the Blue*, ELO
http://home.earthlink.net/~yatescr
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does the C++ standard define the global function of " istream&operator >>(istream& in, string& str); "? xmllmx C++ 5 06-15-2010 11:57 AM
Peeking at the currently selected option in Tk::Optionmenu Alexander Farber Perl Misc 3 07-19-2005 04:08 PM
What DRAM sticks w/o peeking? Andrew Gideon Cisco 1 12-29-2004 03:10 AM
Peeking image Nonyz Javascript 1 02-15-2004 09:23 AM



Advertisments