[gameprogrammer] Re: stupid newbie question: iterating a map

  • From: Brian <brian.ripoff@xxxxxxxxx>
  • To: gameprogrammer@xxxxxxxxxxxxx
  • Date: Mon, 16 Oct 2006 23:33:48 +0100

The sgi STL site is very good. Here is the entry for std::map
"http://www.sgi.com/tech/stl/Map.html";

The iterators in a std::map point to std::pair<> s of <key,data>, so
you can use the std::pair::first and std::pair::second to access the
keys and data elements.

The iterator can be used like so:

typedef std::map< int, playerclass* > PlayerMap;
PlayerMap playerMap;
PlayerMap::iterator it = playerMap.begin();

while( it != playerMap.end() )
{
   int i = it->first;
   playerclass *player = it->second;
}

HTH

On 10/16/06, Roger D Vargas <luo_hei@xxxxxxxx> wrote:
Im using a map to represent a list of players, but I have found a
problem I cant solve using the basic STL reference. I need to iterate
through the whole list
Supposing the list is defined as map<int,*playerclass> what is the
correct way to get the data or the key from iterator?

--
http://dsgp.blogspot.com | Linux, programación, juegos
Have no place I can be since I found Serenity
But you can't take the sky from me


______________________________________________ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com

---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html




--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: