#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <iomanip>

using namespace std;

vector<string> v{ "abvsd","hdvjh","hvdsg","dvass","dvahj","dv","dvar","dvb","jhkfb"};

template <typename RandomIt>
std::pair<RandomIt, RandomIt>
FindStartsWith(RandomIt range_begin, RandomIt range_end,
               const std::string& prefix)
{
    return std::equal_range(range_begin,range_end,prefix,
                            [&prefix](const std::string& a,const std::string& b)
                            {
                                return a.compare(0,prefix.length(),b.substr(0,prefix.length())) < 0;
                            });
}

int main(int argc, const char * argv[])
{
    sort(v.begin(),v.end());
    auto f = FindStartsWith(v.begin(),v.end(),"dva");
    for(auto i = f.first; i != f.second; ++i)
        cout << *i << endl;
}

