File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
SGI-STL Test/container_test/hash_map Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < ext/hash_map>
3
+ #include < cstring>
4
+
5
+ using namespace __gnu_cxx ;
6
+
7
+ using namespace std ;
8
+
9
+ struct eqstr
10
+ {
11
+ bool operator () (const char * s1, const char * s2) const
12
+ {
13
+ return strcmp (s1, s2) == 0 ;
14
+ }
15
+ };
16
+
17
+
18
+ int main ()
19
+ {
20
+ hash_map<const char *, int , hash<const char *>, eqstr> s;
21
+
22
+ cout << s.size () << endl;
23
+
24
+ s[" why" ] = 3 ;
25
+ s[" always" ] = 4 ;
26
+ s[" me" ] = 8 ;
27
+ s[" star" ] = 9 ;
28
+ s[" steve" ] = 18 ;
29
+
30
+ cout << s.size () << endl;
31
+
32
+ cout << " why -> " << s[" why" ] << endl;
33
+ cout << " me -> " << s[" me" ] << endl;
34
+ cout << " star -> " << s[" star" ] << endl;
35
+
36
+ hash_map<const char *, int , hash<const char *>, eqstr>::iterator it = s.begin ();
37
+ for (; it != s.end (); it++) {
38
+ cout << it->first << " " << it->second << endl;
39
+ }
40
+
41
+ return 0 ;
42
+ }
You can’t perform that action at this time.
0 commit comments