


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Let’s look at the example of
map< string, vector
Note that the space between the > > is required. Otherwise, >> is treated as an operator.
m[ string("hello") ]. push_back( 5 );
p = m.find( string( "hello" ) ); p -> second. size()
(p -> second) [ i ] = 15;
(the parentheses are needed because of precedence) or you can use vector iterators:
vector< int > :: iterator q = p -> second. begin() + i; *q = 15;
Both of these, of course, assume that at least i+1 integers have been stored in the vector (either through the use of push back or through construction of the vector).
Write code to count the odd numbers stored in the map
map< string, vector
This will require testing all contents of each vector in the map. Try writing the code using subscripting on the vectors and then again using vector iterators.
Problem: find each word in a text file and record all of the line numbers for each word.
Outline a solution to the word index problem we just solved using a map using a list or a vector instead. Hint: you will need to declare a new class.
map< string, vector
typedef map< string, vector
before your main function (and any function prototypes), then anywhere you want the map you can just use the identifier map_vect:
map_vect :: const_iterator p;
An example solution to a programming problem from a previous semester will be posted on the course web site. The problem involves:
The solution stores the information in a map, with a unique identifier for each computer forming the “key” and a class object that maintains information about a computer and its MP3s as the “value”. It also includes