943,912 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1761
  • C++ RSS
Jun 16th, 2009
0

istream ignore(streamsize = inf, delim) ?

Expand Post »
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!
Last edited by Clockowl; Jun 16th, 2009 at 7:58 pm.
Similar Threads
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Jun 16th, 2009
2

Re: istream ignore(streamsize = inf, delim) ?

Just pass the limit of the stream size type:
C++ Syntax (Toggle Plain Text)
  1. #include <istream>
  2. #include <ios>
  3. #include <limits>
  4.  
  5. in.ignore ( numeric_limits<streamsize>::max(), delim );
Last edited by Narue; Jun 16th, 2009 at 9:36 pm.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Jun 16th, 2009
0

Re: istream ignore(streamsize = inf, 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.
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Jun 17th, 2009
0

Re: istream ignore(streamsize = inf, delim) ?

OH err, the above was a question. xD

"Can you read files larger than 2^32 bytes in a 32 bit environment with streams?"
Reputation Points: 69
Solved Threads: 28
Posting Whiz
Clockowl is offline Offline
376 posts
since May 2008
Jun 17th, 2009
2

Re: istream ignore(streamsize = inf, delim) ?

>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Query Problem
Next Thread in C++ Forum Timeline: sieve of eratosthenes -sieve of eratosthenes segmentation fault





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC