Iterator not work

Joined
May 20, 2012
Messages
1
Reaction score
0
I use Dev c++ , i did one map program, i have the trouble with the iterator creation, and in the for loop my code is given blow please help me


#include <iostream>
#include <map>
#include <string>
using namespace std;

int main ()
{
map<char,string> mymap;
map<char,int>::iterator itr;

mymap.insert(make_pair('A',"Apple"));
mymap.insert(make_pair('B',"Ball"));
mymap.insert(make_pair('C',"Cat"));
mymap.insert(make_pair('D',"Doctor"));

for (itr = mymap.begin();itr != mymap.end();itr++) //Here i have a problem
{
//cout<<"Key:"<<itr->first<<"Value:"<<itr->second<<endl;
cout << (*itr).first << " => " << (*itr).second << endl;
}


cout << "mymap now contains " << (int) mymap.size() << " elements." << endl;
system("pause");
return 0;
}
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top