fork download
  1. #include <map>
  2. #include <string>
  3. #include <algorithm>
  4. #include <iostream>
  5.  
  6. int main() {
  7. std::map <std::string, int> myMap{ {"abc", 1}, {"efg", 2}, {"ijk", 3}, {"iik", 4} };
  8. std::string prefix("i");
  9.  
  10. for (auto it = myMap.lower_bound(prefix); it != std::end(myMap) && it->first.compare(0, prefix.size(), prefix) == 0; ++it)
  11. std::cout << it->first << " -> " << it->second << std::endl;
  12.  
  13. return 0;
  14. }
Success #stdin #stdout 0s 4328KB
stdin
Standard input is empty
stdout
iik -> 4
ijk -> 3