Mail Archives: djgpp/1998/08/26/21:46:25
I've been trying to figure out how to implement the things that Stroustrup is
talking about on djgpp version 2.7.2.1. The documentation offers no working
examples for using STL containers, which, it seems to me, are one of the more
important things about C++.
Below is some code that works on version 2.7.2.1. Since the new version is
out, is the old version's documentation being actively maintained? If it is,
maybe examples like this would help it to be more ... practical.
--Ed (Myknees)
// map.cc implements map container
// based on Stroustrup, 3rd ed., p.483
// had to fiddle to get g++ v.2.7.2.1 happy with it.
#include <map>
#include <_string.h>
#include <iostream.h>
void readitems(map<String, int, less<String> >& m)
{
String word;
int val = 0;
while (cin >> word >> val) m[word] += val;
}
int main(void)
{
map<String, int, less<String> > tbl;
readitems(tbl);
typedef map<String, int, less<String> >::const_iterator CI;
for(CI p = tbl.begin(); p != tbl.end(); ++p)
cout << (*p).first << '\t' << (*p).second << '\n';
return !cin;
}
//end map.cc
result:
[W95]:sh3 map$ a
this 1
that 2
other 3
^Z
other 3
that 2
this 1
- Raw text -