Re: std::map
Ashish <akohli_2004@hotmail.com> wrote:
Is there something different for using std::map in visual studio 2008
I am using one map and inserting some data in it
std::map<const char*,data> mapname;
std::map by default uses operator < to order its keys. In your case, the
map will compare pointers - not the strings they point to. In other
words, if you have two strings that are character-for-character
identical but are stored at different addresses, your map will not
consider them equal. I doubt this is what you want.
Consider using std::map<std::string, data> instead.
This add some data in map at index "character string"
but when i access this mapm from some other function i found the index
becomes corrupt.
What precisely do you mean by "corrupt"? Show your code, explain how you
expect it to work and how actual outcome differs from your expectation.
My guess is, you are inserting a string literal value into the map, and
in another place look up the entry passing the "same" string literal. In
one case, the compiler happens to merge these two string literals into
one; in another, your program actually contains two copies of the same
string data at different addresses. Perhaps you compile with /GF
(Eliminate Duplicate Strings) compiler option on in one case, and off in
another.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925