any sample of std::map as global 
Author Message
 any sample of std::map as global

I need to declare std::map as a global variable.  Then,
add strKey/strValue into map object.  Any body can show a
sample code.  Thanks so much.

Yan



Tue, 13 Dec 2005 13:25:46 GMT  
 any sample of std::map as global

Quote:

> I need to declare std::map as a global variable.  Then,
> add strKey/strValue into map object.  Any body can show a
> sample code.  Thanks so much.

> Yan

No problem, here it is:

// toto.cpp
#include <map>
#include <string>

std::map<std::string, std::string> aMap;

void f()
{
 aMap["key1"] = "danderson";
 aMap["key2"] = "msolot";

Quote:
}

hope this help!

TIPS:
get "Effective STL"

danderson



Tue, 13 Dec 2005 21:00:57 GMT  
 any sample of std::map as global
Also, if you really want the map to be "global", in the sense that you can
use it from any part of your project then you will want to include the
following line in the header file: toto.h for this example.

// toto.h

extern std::map<std::string, std::string> aMap;

that line will declare to any part of the project that includes "toto.h"
that a map by the name of aMap exists somewhere in the project.  So now,
aMap will literally be global to any file in the project that #include's
"toto.h"

Chris



Quote:
> > I need to declare std::map as a global variable.  Then,
> > add strKey/strValue into map object.  Any body can show a
> > sample code.  Thanks so much.

> > Yan

> No problem, here it is:

> // toto.cpp
> #include <map>
> #include <string>

> std::map<std::string, std::string> aMap;

> void f()
> {
>  aMap["key1"] = "danderson";
>  aMap["key2"] = "msolot";
> }

> hope this help!

> TIPS:
> get "Effective STL"

> danderson



Wed, 14 Dec 2005 01:56:53 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing std::set and std::map objects between 2 dlls

2. Global Eng (draft ANSI std dist) address change

3. Exporting STL containers (specifically std::map) from DLL?

4. Help needed on std::map<>

5. Error using Microsoft's implementation of std::map

6. STL, std::allocator and memory mapped files

7. URGENT: STL std::map<ULONG, CEvent>

8. VC7 std::map compilation error

9. std::map

10. std::map

11. std::map gives lots of warning

12. std::map vs CMap

 

 
Powered by phpBB® Forum Software