Iterator not work

Discussion in 'C Programming' started by karthi7787, May 20, 2012.

  1. karthi7787

    karthi7787

    Joined:
    May 20, 2012
    Messages:
    1
    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;
    }
     
    karthi7787, May 20, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hendrik Maryns
    Replies:
    18
    Views:
    1,429
    castillo.bryan@gmail.com
    Dec 22, 2005
  2. greg
    Replies:
    6
    Views:
    460
    Dietmar Kuehl
    Jul 17, 2003
  3. PengYu.UT@gmail.com
    Replies:
    6
    Views:
    653
    Jim Langston
    Oct 30, 2005
  4. Steven D'Aprano

    What makes an iterator an iterator?

    Steven D'Aprano, Apr 18, 2007, in forum: Python
    Replies:
    28
    Views:
    1,172
    Steven D'Aprano
    Apr 20, 2007
  5. David Bilsby
    Replies:
    5
    Views:
    2,052
    David Bilsby
    Oct 9, 2007
Loading...

Share This Page