Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Iterator not work

Reply
Thread Tools

Iterator not work

 
 
karthi7787 karthi7787 is offline
Junior Member
Join Date: May 2012
Posts: 1
 
      05-20-2012
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;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
List iterator assignment fails, assert iterator not dereferencable David Bilsby C++ 5 10-09-2007 02:05 PM
What makes an iterator an iterator? Steven D'Aprano Python 28 04-20-2007 03:34 AM
Difference between Java iterator and iterator in Gang of Four Hendrik Maryns Java 18 12-22-2005 05:14 AM
How to convert from std::list<T*>::iterator to std::list<const T*>::iterator? PengYu.UT@gmail.com C++ 6 10-30-2005 03:31 AM
Iterator doubts, Decision on Iterator usage greg C++ 6 07-17-2003 01:26 PM



Advertisments