list<string> staff;
staff.push_back("Cracker, Carl");
staff.push_back("Hacker, Harry");
staff.push_back("Lam, Larry");
staff.push_back("Sandman, Susan");
list<string>::iterator pos;
pos = staff.begin();
pos++;
pos--;
string value = *pos;
*pos = "Van Dyck, Vicki"; // assign a value
pos = staff.begin(); // assign a position
staff.insert(pos, "Reindeer, Rudolph");
pos = staff.end(); /* points past the end of the list */
staff.insert(pos, "Yaglov, Yvonne");
/* insert past the end of list */
string value = *(staff.end()); /* ERROR */
pos = staff.begin();
while (pos != staff.end())
{ cout << *pos << "\n";
pos++;
}
for (pos = staff.begin(); pos != staff.end(); pos++)
cout << *pos << "\n";
for (i = 0; i < s.size(); i++)
cout << s[i] << "\n";
pos = staff.begin();
pos++;
staff.erase(pos);
stack<string> s;
s.push("Tom");
s.push("Dick");
s.push("Harry");
while (s.size() > 0)
{ cout << s.top() << "\n";
s.pop();
}
queue<string> q;
q.push("Tom");
q.push("Dick");
q.push("Harry");
while (q.size() > 0)
{ cout << q.front() << "\n";
q.pop();
}
set<string> s;
s.insert("Tom");
s.insert("Dick");
s.insert("Harry");
set<string>::iterator p;
for (p = s.begin(); p!= s.end(); p++)
cout << *p << "\n";
set<string> s;
s.insert("Tom");
s.insert("Tom");
cout << s.count("Tom") << "\n"; /* displays 1 */
multiset<string> m;
m.insert("Tom");
m.insert("Tom");
cout << m.count("Tom") << "\n"; /* displays 2 */
map<string, double> scores;
scores["Tom"] = 90;
scores["Dick"] = 86;
scores["Harry"] = 100;
multimap<string, double> mmap;
mmap.insert(pair("Tom", 90));
mmap.insert(pair("Dick", 86));
mmap.insert(pair("Harry", 100));
mmap.insert(pair("Tom", 190));
vector<double> data;
/* do something with data */
double vsum = 0;
accumulate(data.begin, data.end(), vsum);
/* now vsum contains the sum of the elements in the vector */
list<double> salaries;
/* do something with salaries */
double lsum = 0;
accumulate(salaries.begin(), salaries.end(), lsum);
/* now lsum contains the sum of the elements in the list */
/* search for a certain name on the staff */
list<string>::iterator it =
find(staff.begin(), staff.end(), name);