|
From: Mike Copeland on 13 Apr 2008 12:13 I have an STL map declared: struct CLIENTSTRUCT // Individual Department info int clientKey; // ClientKey int enrollKey; // Enrollment ClientKey int guarantorKey; // Guarantor ClientKey string clientName; // Client Name } clientWork; typedef map<int, CLIENTSTRUCT> CLIENTS; CLIENTS clientData; map<int, CLIENTSTRUCT>::const_iterator cIter; I have seccessfully been able to populate the map with initial data (via .insert), but I can't figure out how to _update_ the map objects. Specifically, I need to modify rhe "enrollKey" and "guarantorKey" elements of various objects after I use .find and the iterator cIter. None of my references (nor google) points me in the right direction. Please advise TIA
From: Andrew Koenig on 13 Apr 2008 12:19 "Mike Copeland" <mrc2323(a)cox.net> wrote in message news:MPG.226bdf2ae67b58d19896f9(a)news.cox.net... > typedef map<int, CLIENTSTRUCT> CLIENTS; > CLIENTS clientData; > map<int, CLIENTSTRUCT>::const_iterator cIter; > I have seccessfully been able to populate the map with initial data > (via .insert), but I can't figure out how to _update_ the map objects. > Specifically, I need to modify rhe "enrollKey" and "guarantorKey" > elements of various objects after I use .find and the iterator cIter. If you want to change the elements of the map, you should be using iterator, not const_iterator: map<int, CLIENTSTRUCT>::iterator cIter; After that, you can write citer->second.enrollKey = /* whatever */; citer->second.guarantorKey = /* whatever */; Or, alternatively: CLIENTSTRUCT& cs = citer->second; cs.enrollKey = /* whatever */; cs.guarantorKey = /* whatever */;
|
Pages: 1 Prev: Lesson 5, Arrays, Static, Dynamic, Multi Dimesional. Next: concatenate vector of strings |