Tools.h++ Manual
16-4 104011 Tandem Computers Incorporated
16
Program output:
2
Here’s the line-by-line description:
4 On this line, the function
RWvistream& operator>>(RWvistream&, RWCollectable&);
restores the contents of the
SortedCollection
from the input virtual
stream
istr
.
5 A temporary string with value “George” is created in order to search for
a string within the newly created
SortedCollection
with the same
value.
6 The
SortedCollection
is searched for an occurrence of a string with
value “George”. The pointer "
g
" points to such a string.
// Read the collection back in:
istr >> sc2; // 4
RWCollectableString temp("George"); // 5
// Find a "George":
RWCollectableString* g =
(RWCollectableString*)sc2.find(&temp); // 6
// "g" now points to a string with the value "George"
// How many occurrences of g are there in the collection?
unsigned count = 0; // 7
SortedCollectionIterator sci(sc2); // 8
RWCollectableString* item;
while ( item = (RWCollectableString*)sci() ) // 9
if ( item==g ) //10
count++;
cout << count;
sc2.clearAndDestroy(); //11
return 0;
}