fork(1) download
  1. #include <vector>
  2. #include <string>
  3. #include <algorithm>
  4. #include <iostream>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. vector<string> v{ "abvsd","hdvjh","hvdsg","dvass","dvahj","dv","dvar","dvb","jhkfb"};
  10.  
  11. template <typename RandomIt>
  12. std::pair<RandomIt, RandomIt>
  13. FindStartsWith(RandomIt range_begin, RandomIt range_end,
  14. const std::string& prefix)
  15. {
  16. return std::equal_range(range_begin,range_end,prefix,
  17. [&prefix](const std::string& a,const std::string& b)
  18. {
  19. return a.compare(0,prefix.length(),b.substr(0,prefix.length())) < 0;
  20. });
  21. }
  22.  
  23. int main(int argc, const char * argv[])
  24. {
  25. sort(v.begin(),v.end());
  26. auto f = FindStartsWith(v.begin(),v.end(),"dva");
  27. for(auto i = f.first; i != f.second; ++i)
  28. cout << *i << endl;
  29. }
  30.  
  31.  
Success #stdin #stdout 0s 4148KB
stdin
Standard input is empty
stdout
dvahj
dvar
dvass