map::upper_bound
#include <map>
#include <iostream>
using std::map,
std::pair,
std::cerr;
typedef map<std::string, int> my_map;
typedef pair<std::string, int> my_pair;
std::ostream& operator<<(std::ostream& os, my_map const& map)
{
os << "{ ";
int count = 0;
for (my_pair p : map){
os << "'" << p.first << "' is " << p.second ;
if (count < map.size() - 1){
os << ", ";
}
++count;
}
return os << "}";
}
int main(){
my_map a{{"v", 224}, {"w", 425}, {"x", 192}};
my_map::iterator ubi = a.upper_bound("w");
cerr << "upper_bound for c: " << ubi->first << " " << ubi->second << "\n";
return 0;
}
C++ Examples© 2024 TBD