Topic: map iterator in Borland C++ Builder?
Author: Edward Diener <eddielee@abraxis.com>
Date: 1998/03/12 Raw View
If you change lines 20 and 21 to:
sum += (*p).second;
cout << (*p).first << '\t' << (*p).second << endl; //
it works fine with BC++ 5.02 or Borland C++ Builder 3.
The RogueWave implementation probably does not have a -> operator for STL
iterators.
Markus Pesti wrote:
> Bjarne Stroustrup's map-example produces a compiler error while
> accessing the iterators (lines 20 and 21):
>
> //--------------------------------------------------------------------------
> -
> 01 #include <string>
> 02 #include <map>
> 03 #include <iostream>
> 04 using namespace std;
>
> 05 void readitems (map<string, int, less<string> >& m)
> 06 {
> 07 string word;
> 08 int value = 0;
> 09 while (cin >> word >> value)
> 10 m[word] += value;
> 11 }
>
> 12 int main(int argc, char **argv)
> 13 {
> 14 map<string, int, less<string> > tbl;
> 15 readitems(tbl);
>
> 16 int sum = 0;
> 17 typedef map<string, int, less<string> >::const_iterator CI;
>
> 18 for(CI p = tbl.begin(); p != tbl.end(); ++p)
> 19 {
> 20 sum += p->second;
> // <-------------------------------------------------------------
> 21 cout << p->first << '\t' << p->second << endl; //
> <-------------------------------------------------------------
> 22 }
>
> 23 cout << "sum:\t" << sum << endl;
>
> 24 return !cin;
> 25 }
> //--------------------------------------------------------------------------
> -
>
> With the MS CV++ 5 compiler the example works properly.
> Is there anybody who knows what's wrong there?
>
> Thanks Markus
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: "Markus Pesti" <Markus@Pesti.L.uunet.de>
Date: 1998/03/11 Raw View
Bjarne Stroustrup's map-example produces a compiler error while
accessing the iterators (lines 20 and 21):
//--------------------------------------------------------------------------
-
01 #include <string>
02 #include <map>
03 #include <iostream>
04 using namespace std;
05 void readitems (map<string, int, less<string> >& m)
06 {
07 string word;
08 int value = 0;
09 while (cin >> word >> value)
10 m[word] += value;
11 }
12 int main(int argc, char **argv)
13 {
14 map<string, int, less<string> > tbl;
15 readitems(tbl);
16 int sum = 0;
17 typedef map<string, int, less<string> >::const_iterator CI;
18 for(CI p = tbl.begin(); p != tbl.end(); ++p)
19 {
20 sum += p->second;
// <-------------------------------------------------------------
21 cout << p->first << '\t' << p->second << endl; //
<-------------------------------------------------------------
22 }
23 cout << "sum:\t" << sum << endl;
24 return !cin;
25 }
//--------------------------------------------------------------------------
-
With the MS CV++ 5 compiler the example works properly.
Is there anybody who knows what's wrong there?
Thanks Markus
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]