Re: map problem
map<char*, vector<char*> >::iterator it2 = data_container.find( "dynamic_selection" );
if( it2==data_container.end() )
{
printf("NOT FOUND!\n");
}
else
{ printf("FOUND\n");
printf("Size:%d\n", (*it2).second.size() );
}
This always prints "NOT FOUND".
I can't see what's wrong!
At a guess it is because you are storing pointers. Two identical strings
will have different addresses unless they are the same string.
My first response was the same: char*'s will be compared as pointers.
Using Visual Studio 2008 I ran the following code, which as far as I
see reconstructs the OP's problem.
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
map<char*, vector<char*> > data;
data["foo"] = vector<char*>();
data["foo"].push_back("foo.bar");
data["foo"].push_back("foo.baz");
data["bar"] = vector<char*>();
data["bar"].push_back("bar.bar");
data["bar"].push_back("bar.baz");
if (data.find("foo") == data.end())
cout << "not found" << endl;
else
cout << "found" << endl;
}
Strangely enough the output is "found". Anyone has an explanation?
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]