Saving and restoring streampos's

W

Wolfgang Thomsen

Hello,

I need to process very large files which are made of blocks of data. To
speed up the reading of a specific block, I let my program note down the
streampos of each block's beginning in a file, which seems to work.

For reading the stream positions back, I use the following code:

while(!indexfile.eof()) {
int position;
indexfile >> position;
//.. save position into a vector ..
}

which does not work because the numerical streampositions exceed the size of
an int.

while(!indexfile.eof()) {
streampos position;
indexfile >> position;
//.. save position into a vector ..
}

does not work either and gives me an error message
"error: ambiguous overload for operator>> in
((XYZFile*)this)->XYZFile::indexfile >> position"

(XYZFile is the name of the class).

It also gives me a long list of possible candidates, but I do not know how
to specify which it should use, let alone decide which one I should use.


Any help or suggestions are greatly appreciated,
regards, Wolfgang
 
J

James Kanze

I need to process very large files which are made of blocks of data. To
speed up the reading of a specific block, I let my program note down the
streampos of each block's beginning in a file, which seems to work.
For reading the stream positions back, I use the following code:
while(!indexfile.eof()) {

Which is surely wrong. istream::eof() is only significant after
a read has failed.
int position;
indexfile >> position;
//.. save position into a vector ..
}
which does not work because the numerical streampositions exceed the size of
an int.

So use a larger type:). (In practice, of course, streampos
should be a class type, and likely isn't representable in any
integral type.)
while(!indexfile.eof()) {
streampos position;
indexfile >> position;
//.. save position into a vector ..
}
does not work either and gives me an error message
"error: ambiguous overload for operator>> in
((XYZFile*)this)->XYZFile::indexfile >> position"
(XYZFile is the name of the class).
It also gives me a long list of possible candidates, but I do not know how
to specify which it should use, let alone decide which one I should use.

There isn't one that would work. That's why it's ambiguous: all
are equally bad.
Any help or suggestions are greatly appreciated,

There's no real solution within the standard here. I'd use the
system API (Posix, Windows or whatever), with [io]stringstream
for parsing and formatting.
 

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

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top