Hey guys,

Can I tell istream to ignore ALL the characters until the delimiter char? It can be done with a loop but it's kinda weird I can't tell istream "discard until this char" imho, so maybe there's an hidden option somewhere.

Thanks in advance!

7 Years
Discussion Span
Last Post by Narue

Just pass the limit of the stream size type:

#include <istream>
#include <ios>
#include <limits>

in.ignore ( numeric_limits<streamsize>::max(), delim );

Say that's a regular int (assuming 4 bytes), you can't open files more than ~5GB in a 32-bit environment (since the stream can't be bigger than that).

Thanks for that though! I used MAX_INT before, but this is definitely better.


OH err, the above was a question. xD

"Can you read files larger than 2^32 bytes in a 32 bit environment with streams?"


>Can you read files larger than 2^32 bytes in a 32 bit environment with streams?
The short answer is yes. The long answer is that whether it's built into the standard streams is up to the implementation. A good implementation should be able to handle anything the target system throws at it. For example, I would expect the underlying type for streampos to be __int64 on an NTFS Windows implementation.

However, we're not talking about being able to process large files (where streampos would be the primary culprit for failures), we're talking about streamsize. The streamsize type is the size of the stream buffer, which is very likely to be smaller than the allowed maximum size of a file, and that's a good thing.

If you have a large file and need to ignore all of it up to the delimiter, you'd find it easier to use a traditional loop because there's not a good way to determine how istream::ignore terminated if it didn't reach end-of-file. Alternatively, you can write your own streambuf to increase the size of the internal buffer, but that has debatable value in this case.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.