How to find a single word in "std::vector<char>" container
c++, find, search, stl, vector
Solution
You don't need to put the pattern you're looking for into a container. A C string is enough.
std::vector<char> v = ....;
const char *crlf2 = "\r\n\r\n";
auto it = std::search(v.begin(), v.end(), crlf2, crlf2 + strlen(crlf2));
Anyway, after this, `it` will contain an iterator into the vector `v` where that pattern begins (or `v.end()` if the pattern is not found).
You can convert that into an index with `std::distance(v.begin(), it)` or just `it - v.begin()`
Problem
I have a mixed binary (i.e. image) and some human readable data (i.e. HTTP header) stored in the "`std::vector<char>`" container. (Data is separated by "CRLFCRLF (\r\n\r\n)" indicator) Can anyone suggest a way on how to find a start position of "\r\n\r\n" in the "`std::vector<char>`" container? Is it possible to do something like "`std::size_t pos = data.find("\r\n\r\n");` (where data is a "`std::vector<char>`")" using STL library? Thanks.