delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/26/21:46:25

From: myknees AT aol DOT com (Myknees)
Newsgroups: comp.os.msdos.djgpp
Subject: STL documentation for version 2.7.2.1 needed?
Lines: 52
Message-ID: <1998082701352700.VAA00961@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
Date: 27 Aug 1998 01:35:27 GMT
References: <19980424035042 DOT AAD8293 AT ppp125 DOT cartsys DOT com>
Organization: AOL http://www.aol.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019