
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