Re: Handling large text streams of integers
James Kanze wrote:
On Mar 31, 7:14 pm, Comp1...@yahoo.co.uk wrote:
Suppose infile is an ifstream bound to a text file containing
integers. The operation infile >> x1; reads integers into the
stream. How many times can this operation be done before
there are possible problems?
As many times as there are numbers in the file.
I know this question isn't exactly platform independent but
are there guidelines that can be given for writing portable
code?
The real guideline is the check the results after every
extraction.
How does the number of such operations (before using another
stream) compare with
std::numeric_limits<std::streamsize>::max() ?
A lot of systems maintain the current position in the file in an
std::streamsize. Which means that
std::numeric_limits<std::streamsize>::max() is also the maximum
number of bytes in the file. And that there can't be that many
numbers, since each number requires at least two bytes (one
digit and a separator).
[..]
What if the "file" is actually a serial connection that, like the
Energizer Bunny, just keeps going, and going, and... Will the system
also try to keep track of the "current position" on a socket, for
example? I know, I know, the OP asked about a text file...
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask