Determine whether one vector is a prefix of the other
For a prefix search, you can use std::mismatch() in &lt;algorithm&gt;.

bool isPrefix(const std::vector&lt;int&gt;&amp; v1, const std::vector&lt;int&gt;&amp; v2) {
    if (v1.size() &gt; v2.size()) {
        return v2.end() == std::mismatch(v2.begin(), v2.end(), v1.begin()).first;
    }
    return v1.end() == std::mismatch(v1.begin(), v1.end(), v2.begin()).first;
}