istream ignore(streamsize = inf, delim) ?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 375
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

istream ignore(streamsize = inf, delim) ?

 
0
  #1
Jun 16th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,695
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 728
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
2
  #2
Jun 16th, 2009
Just pass the limit of the stream size type:
  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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 375
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

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

 
0
  #3
Jun 16th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 375
Reputation: Clockowl is on a distinguished road 
Solved Threads: 27
Clockowl's Avatar
Clockowl Clockowl is offline Offline
Posting Whiz

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

 
0
  #4
Jun 17th, 2009
OH err, the above was a question. xD

"Can you read files larger than 2^32 bytes in a 32 bit environment with streams?"
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,695
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 728
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
2
  #5
Jun 17th, 2009
>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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC