How to interate map

F

free2cric

Hi ,
I am using stl map

struct elmStructure
{
int type;
int num;
};

map <string, tempStructure> c_elmmap;
char mapStr[200];

in my code, I define mapStr, tempStructure tStr
and populate my map as

tStr.type = 7; tStr.num = 1700;
sprintf(mapStr,"%d%d", tStr.type, tStr.num);

c_elmmap[mapStr] = tStr;
and so onn....


I want to visit all the mapped structures

map <string, elmStructure> :: iterator MyIterator ;

MyIterator = c_elmmap.begin();

while(MyIterator != c_elmmap.end())
{
//elmStructure& temp =
MyIterator++;
}

so please tell me elmStructure& temp = ?????????? in above block

Thanks Am I going correctly in defining map as shown above.
Thanks,
cric
 
W

Winbatch

Hi ,
I am using stl map

struct elmStructure
{
int type;
int num;
};

map <string, tempStructure> c_elmmap;
char mapStr[200];

in my code, I define mapStr, tempStructure tStr
and populate my map as

tStr.type = 7; tStr.num = 1700;
sprintf(mapStr,"%d%d", tStr.type, tStr.num);

c_elmmap[mapStr] = tStr;
and so onn....


I want to visit all the mapped structures

map <string, elmStructure> :: iterator MyIterator ;

MyIterator = c_elmmap.begin();

while(MyIterator != c_elmmap.end())
{
//elmStructure& temp =
MyIterator++;
}

so please tell me elmStructure& temp = ?????????? in above block

Thanks Am I going correctly in defining map as shown above.
Thanks,
cric

elmStructure & temp = myIterator->second;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top