| | |
istream ignore(streamsize = inf, delim) ?
![]() |
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 6: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 8:36 pm.
In case you were wondering, yes, I do hate you.
>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.
In case you were wondering, yes, I do hate you.
![]() |
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
Views: 858 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
algorithm api array arrays assignment beginner binary c++ c/c++ calculator char class classes code compile compiler constructor conversion convert count delete dll dynamic encryption error file files filestream fstream function functions game givemetehcodez graph graphics gui homework iamthwee input int lazy lib linker list loop loops map math matrix member memory newbie number object objects opengl output parameter pointer pointers problem program programming project python qt random read reading recursion recursive reference server sockets sort sorting spoonfeeding string strings struct student studio template templates text time tree undefined url variable vc++ vector video visual visualstudio win32 window windows winsock wordfrequency






