Re: ifstream and reading way past the EOL
- From: Ulrich Eckhardt <eckhardt@xxxxxxxxxxxxxx>
- Date: Tue, 20 Sep 2005 15:19:52 +0200
sklett wrote:
> I am parsing a text file, when I know that I have hit a certain section
> that indicates I no longer need to read and interpret the rest of the
> file, but simply store it to write out later I do this:
> <code>
> // read the rest of the file into a single buffer
> int position = m_inStream.tellg();
tellg() doesn't return an int.
> m_inStream.seekg (0, ios::end);
> int end = m_inStream.tellg();
tellg() doesn't return anything valid when you are at the end of the stream,
IIRC.
Also, you failed to check the returnvalue of your read() operations. Asking
for help without checking for errors... tsk, tsk, tsk ;)
Try something along these lines (check the proper use of the functions and
types):
std::deque<char> buffer;
char tmp[100];
unsigned amount;
while( amount = in.readsome( tmp, 100))
buffer.insert( buffer.end(), tmp, tmp+amount);
Alternatively, use std::getline() in combination with a list<string>.
Hmmm, maybe the easiest thing is to use the fact that ostream have an
overload for streabuffer-pointers:
// store rest of file in m_tailing_data
std::stringstream tmp;
tmp << m_inStream.rdbuf();
m_tailing_data = tmp.str();
Uli
.
- Follow-Ups:
- Re: ifstream and reading way past the EOL
- From: Stephen Howe
- Re: ifstream and reading way past the EOL
- From: sklett
- Re: ifstream and reading way past the EOL
- References:
- ifstream and reading way past the EOL
- From: sklett
- ifstream and reading way past the EOL
- Prev by Date: ifstream and reading way past the EOL
- Next by Date: problem use stl with vc 6.0
- Previous by thread: ifstream and reading way past the EOL
- Next by thread: Re: ifstream and reading way past the EOL
- Index(es):
Relevant Pages
|