I
Igor R.
Hello,
I want to find the latest occurance of some sequence in a binary file.
Intuitively, it seems that the shortest way is:
ifstream file("myfile", std::ios::binary|std::ios::in);
std::string delim("\r\n\r\n"); // sequence to search
typedef std::istreambuf_iterator<char> iterator;
iterator begin(file), end;
iterator pos = std::find_end(begin, end, delim.begin(), delim.end());
However, it doesn't work, because std::find_end requires
ForwardIterator, while istreambuf_iterator is an InputIterator. On
MSVC 9.0 So the above code just crashes!
So, I've got 2 questions:
1) Why std::find_end doesn't enforce its requirements at compile time?
What does standard say about such a behavior?
2) How to make InputIterator out of istreambuf_iterator?
Thanks!
I want to find the latest occurance of some sequence in a binary file.
Intuitively, it seems that the shortest way is:
ifstream file("myfile", std::ios::binary|std::ios::in);
std::string delim("\r\n\r\n"); // sequence to search
typedef std::istreambuf_iterator<char> iterator;
iterator begin(file), end;
iterator pos = std::find_end(begin, end, delim.begin(), delim.end());
However, it doesn't work, because std::find_end requires
ForwardIterator, while istreambuf_iterator is an InputIterator. On
MSVC 9.0 So the above code just crashes!
So, I've got 2 questions:
1) Why std::find_end doesn't enforce its requirements at compile time?
What does standard say about such a behavior?
2) How to make InputIterator out of istreambuf_iterator?
Thanks!