| | |
istream ignore(streamsize = inf, delim) ?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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!
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.
Just pass the limit of the stream size type:
C++ Syntax (Toggle Plain Text)
#include <istream> #include <ios> #include <limits> 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.
>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.
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.
![]() |
Similar Threads
- How do I flush the input stream? (C++)
- getline from file? (C++)
- cin.ignore (C++)
- string arrays: storing input (C++)
- Parse from a textBox (C++)
- converting from char to ASCII to char (C++)
- C++ Stream_Var.getline function (C++)
- ignore function (C++)
- system("PAUSE") (C++)
Other Threads in the C++ Forum
- Previous Thread: Query Problem
- Next Thread: sieve of eratosthenes -sieve of eratosthenes segmentation fault
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






