I have 2 char arrays like "const char *arr1[ArrSize] = {"Blah1", "Wibble1", "Shrug1"};". For putting them into a vector I found a nice quick solution:
void fillVecTest()
{
const int ArrSize = 3;
const char *arr1[ArrSize] = {"Blah1", "Wibble1", "Shrug1"};
const char *arr2[ArrSize] = {"Blah2", "Wibble2", "Shrug2"};
std::vector<std::string> vec1(arr1, arr1+ArrSize);
std::vector<std::string> vec2(arr2, arr2+ArrSize);
std::vector<std::string>::iterator l_It1Vec1;
std::vector<std::string>::iterator l_It = vec1.end();
l_It = find(vec1.begin(), vec1.end(), std::string("Blah1"));
if(l_It != vec1.end())
{
size_t l_pos = l_It - vec1.begin();
printf("found %s, pos=%u val: %s\n", l_It->c_str(),l_pos, vec2[l_pos].c_str());
}
}
Now I thought it should be also possible to put both directly into a map as arr1 is the key and arr2 is the value. I tried some ways but I didn't succeed.
void fillMapTest()
{
const int ArrSize = 3;
const char *arr1[ArrSize] = {"Blah1", "Wibble1", "Shrug1"};
const char *arr2[ArrSize] = {"Blah2", "Wibble2", "Shrug2"};
std::map<std::string,std::string> map1;//(pair(arr1,arr1), pair(arr1+ArrSize,arr2+ArrSize));
std::map<std::string,std::string>::iterator l_It1Map1;
//l_It1Map1 = find(map1.begin(), map1.end(), std::string("Blah1"));
if(l_It1Map1 != map1.end())
{
printf("found key: %s, val: %s\n",l_It1Map1->first.c_str(), l_It1Map1->second.c_str());
}
}
int _tmain(int /*argc*/, _TCHAR* /*argv[]*/)
{
fillVecTest();
fillMapTest();
return 0;
}
I think that just the commented lines in function "fillMapTest" would need to be solved. Constuctor and find don't work like I want.
Please has any STL expert an idea?