472,353 Members | 1,248 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

Peeking an entire line from an istream

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

Jan 14 '06 #1
2 5416

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

Jan 14 '06 #2
"in*****@gmail.com" <in*****@gmail.com> 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."
%%%% <ya***@ieee.org> % 'Big Wheels', *Out of the Blue*, ELO
http://home.earthlink.net/~yatescr
Jan 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: balgach | last post by:
Greetings all, I have a group of rather large files (by group i mean close to 2x10^7 files, each 12-15megs) now i need information which is...
2
by: Eric Lilja | last post by:
Hello, I'm writing a simple program that upon start-up needs to open a text file and read a value on the last line. Then all other accesses to the...
1
by: ricky | last post by:
I am a student doing internship. Iam doing a project. I need to remove or update a line in the file. So far 1.I can read from file 2. I can write...
3
by: Ivan Liu | last post by:
I would like know how I can skip a line while reading a set of input data (from a text file) if the first character of the line is "#". My...
4
by: owolablo | last post by:
I'm trying to make a subprogram, Code: void file2String(istream& in, string& theFile) that can read an entire file into a string variable,...
13
by: Gianni Mariani | last post by:
What I would like to do is read bytes from a stream, any number and any time. I would like it to wait until there are any bytes to read. I want...
24
by: Ground21 | last post by:
Hello. How could I read the whole text file line after line from the end of file? (I want to ~copy~ file) I want to copy file in this way: ...
6
by: Thomas Kowalski | last post by:
Hi, currently I am reading a huge (about 10-100 MB) text-file line by line using fstreams and getline. I wonder whether there is a faster way to...
4
by: raven.mp4 | last post by:
Hi. Is there any function like getline which loads specified line from a text file? Something like getline(myfile, line, 10); where 10 means 10th...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.