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?
How do we find an element using STL? Approach 1: Return index of the element using std::find() Use std::find_if() with std::distance() Use std::count()
util. vector. contains() method is used to check whether a specific element is present in the Vector or not. So basically it is used to check if a vector contains any particular element or not.
The concatenation of vectors can be done by using combination function c. For example, if we have three vectors x, y, z then the concatenation of these vectors can be done as c(x,y,z). Also, we can concatenate different types of vectors at the same time using the same same function.
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With