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)

Reply
 
Thread Tools Display Modes
  #1  
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
  #2  
Old 07-06-2009, 11:14 PM
gaeorn
Developer
 
Join Date: Apr 2009
Location: USA
Posts: 478
Default

Quote:
Originally Posted by KLS View Post
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.
That is correct. If you write it as >>, g++ will throw an error. Writing it as > > with a space between them will work find with g++. I'm using g++ 4.3.2, so fairly recent.
Reply With Quote
Reply

Thread Tools
Display Modes

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 02:22 AM.


 

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