[Cs3] assigning to map elements through iterator

Mikhail Nesterenko mikhail at cs.kent.edu
Wed Jun 24 13:12:22 EDT 2015


CS3 students,

I figured out why the code in today's lecture did not work. I was
trying to assing the _whole pair_ to an element in a map through
iterator. This means that I might be potentially modifying the key
(and damaging the internal structure of the map). This is not
allowed. This is the way to do what I wanted to do:

   months.insert(std::make_pair("february", 28));

Alternatively, the value of a pair may be modified:

    months.find("january")->second = 55;

Thanks,
-- 
Mikhail


More information about the cs3 mailing list