Looking to find a C++ STL vector inside an STL vector

c++, find, stl, vector

Solution

It looks like you want to search for a subsequence inside another sequence. You can do that with `std::search` from the Standard Library.

auto it = std::search(v2.begin(), v2.end(), v1.begin(), v1.end());

Problem

I am trying to see if vector v1 is contained within vector v2. My vectors are ordered and it is required that the order is preserved. For example, if v1= (a, b) and v2 = (e, f, a, b), I would like to get an iterator pointing to a in v2. STL `find` only finds one object inside a vector. I guess what I want is something similar to `string::find`. Is there any function in STL for doing this?

Original source

Related problems