From vectors to maps to output streams, the C++ standard library has everything you want or need. This post will contain small snippets of different classes that you can find in the std. You can find more documentation here.
#include <map>
//Map is a balanced BST// or std::map<string, int> m = { {"first", 1}, {"second", 2}, {"third", 3} };std::map<string,int>m;m["first"]=1;m["second"]=2;m["third"]=3;std::pair<string,int>p("forth",4);m.insert(p);// { "first":1, "second":2, "third":3, "forth":4 }// auto = std::pair<string,int>::iteratorfor(autoit=m.begin();it!=m.end();++it){std::cout<<it->first<<" "<<it->second<<std::endl;}/*
first 1
second 2
third 3
forth 4
*/intforth=m["forth"];// forth = 4// it is an iterator that points to the pair whose key is "second"// the find method runs in O(log n) time since it's a BSTautoit=mymap.find("second");m.erase(it);// { "first":1, "third":3, "forth":4 }m.erase("forth");// { "first":1, "third":3 }
Set
1
2
3
4
5
6
7
8
9
10
11
12
#include <set>
// or std::set<std::string> s = {"first", "second", "third", "forth"};std::set<std::string>s;s.insert("first");s.insert("second");s.insert("third");s.insert("forth");autoit=s.find("second");s.erase(it);// { "first", "third", "forth" }s.erase("forth");// { "first", "third" }