Debian Codegraph @

yo/containers/examples/mapinsert.cc

raw
1 #include <iostream>
2 #include <string>
3 #include <map>
4 using namespace std;
5
6 int main()
7 {
8 pair<string, int> pa[] =
9 {
10 pair<string,int>("one", 10),
11 pair<string,int>("two", 20),
12 pair<string,int>("three", 30),
13 };
14 map<string, int> object(&pa[0], &pa[3]);
15
16 // {four, 40} and `true' is returned
17 pair<map<string, int>::iterator, bool>
18 ret = object.insert
19 (
20 map<string, int>::value_type
21 ("four", 40)
22 );
23
24 cout << boolalpha;
25
26 cout << ret.first->first << " " <<
27 ret.first->second << " " <<
28 ret.second << " " << object["four"] << '\n';
29
30 // {four, 40} and `false' is returned
31 ret = object.insert
32 (
33 map<string, int>::value_type
34 ("four", 0)
35 );
36
37 cout << ret.first->first << " " <<
38 ret.first->second << " " <<
39 ret.second << " " << object["four"] << '\n';
40 }
41 /*
42 Generated output:
43
44 four 40 true 40
45 four 40 false 40
46 */