Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 07-06-2009, 02:44 AM
KLS
Administrator
 
Join Date: Sep 2006
Posts: 1,348
Default

I wrote up a simple example that should be fairly informative with regards to nesting one map in another. Keep in mind something the >> on the end of the map decl doesn't compile on g++, which is why it's > >, gnu translates it as an operator instead of apart of the declaration. At least last time I tried it this was the case.

Code:
#include <stdio.h>
#include <iostream>
#include <string>
#include <map>

int main()
{
	std::map<int, std::map<int, std::string> > some_double_map;

	std::map<int, std::string> string_map;
	string_map[1] = "Wow";
	string_map[9] = "Bonk";

	std::map<int, std::string> string_map_two;
	string_map_two[3] = "Rich";
	string_map_two[1] = "Test";

	some_double_map[0] = string_map;
	some_double_map[1] = string_map_two;

	std::map<int, std::map<int, std::string> >::iterator iter = some_double_map.find(0);

	if(iter != some_double_map.end())
	{
		std::map<int, std::string>::iterator iter_inner = iter->second.find(1);
		if(iter_inner != iter->second.end())
		{
			printf("Found string %s\n", iter_inner->second.c_str());
		}
		else
		{
			printf("Failed to find string =(\n");
		}
	}
	else
	{
		printf("Failed to find std::map =(\n");
	}

	iter = some_double_map.find(1);
	if(iter != some_double_map.end())
	{
		std::map<int, std::string>::iterator iter_inner = iter->second.find(1);
		if(iter_inner != iter->second.end())
		{
			printf("Found string %s\n", iter_inner->second.c_str());
		}
		else
		{
			printf("Failed to find string =(\n");
		}
	}
	else
	{
		printf("Failed to find std::map =(\n");
	}

	std::cin.get();
	return 0;
}
Reply With Quote
 


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

Forum Jump

   

All times are GMT -4. The time now is 09:36 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3