KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm using std::map in such a way: #include <map> #include <string> #include <iostream> using namespace std; int main(int argc, char* argv[]) { map<string, int> my_map; my_map.insert(pair<string, int>("Ab", 1)); my_map.insert(pair<string, int>("Abb", 2)); my_map.insert(pair<string, int>("Abc", 3)); my_map.insert(pair<string, int>("Abd", 4)); my_map.insert(pair<string, int>("Ac", 5)); my_map.insert(pair<string, int>("Ad", 5)); cout<<my_map.lower_bound("Ab")->second<<endl; cout<<my_map.upper_bound("Ab")->second<<endl; return 0; } http://ideone.com/5YPQmj I'd like to get all values whose key starts with a particular string (for example "Ab"). I can easily get the begin iterator using map::lower_bound. But how can I get an upper bound? Do I have to iterate the whole set starting at lower bound and check every key if it still starts with "Ab"?
Tags (comma-separated)
Save Edits
Cancel