Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. index of member of a map?

index of member of a map?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabase
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zon_cpp
    wrote on last edited by
    #1

    hi, how do i know index of an iterator of a map?

    map::iterator it = mymap.find(3);

    i want to know index of 'it' in mymap???

    Zo.Naderi-Iran

    _ C 2 Replies Last reply
    0
    • Z zon_cpp

      hi, how do i know index of an iterator of a map?

      map::iterator it = mymap.find(3);

      i want to know index of 'it' in mymap???

      Zo.Naderi-Iran

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You can increment a counter in a loop. But why do you need this. std::map always works on the key and so you must not use the index to perform any operations on the map. Here is something you could do -

      map num;
      int j = 0;
      for (auto i = num.begin(); i != num.end(); ++i, ++j)
      {
      if ((*i).first == 5)
      cout << j << endl;
      }

      Don't know if there is any other way to do this.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      1 Reply Last reply
      0
      • Z zon_cpp

        hi, how do i know index of an iterator of a map?

        map::iterator it = mymap.find(3);

        i want to know index of 'it' in mymap???

        Zo.Naderi-Iran

        C Offline
        C Offline
        Chris Losinger
        wrote on last edited by
        #3

        maps are not arranged in a simple linear order (they are trees), so there is no 'index' for an item.

        image processing toolkits | batch image processing

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups