- 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;
}
#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;
}