views:

81

answers:

1

Hello, I need to index specific strings with other strings and I can't really find a good way to do so. I tried to use tr1::unordered_map, but I'm having some difficulties using it. If someone could tell me what is the best way to do that I'd be really grateful :) I also need to index objects by a number (numbers are not in order so I can't use a vector)

+7  A: 

What about std::map?

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

Then you can add elements,

foo["bar"] = "baz";
cout << foo["bar"] << std::endl;  // baz
Alex
Im trying to use this: std::map<std::string, std::string> lang;std::string fMatch(matches[2].first, matches[2].second);std::string sMatch(matches[6].first, matches[6].second);lang[fMatch] = sMatch; but I'm getting this error: error C2679: binary '[' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
Michael S.
Can you post a minimal test-case in your question, along with the compiler output? That code looks reasonable.
Alex
first header: http://pastebin.com/1M6p55fG, second header: http://pastebin.com/e74mpFwj, code file: http://pastebin.com/rMbyBdbU, output: http://pastebin.com/wy57wMjC
Michael S.
@mcco: You have two variables named `lang`. One is a member of the class `LocalCacheLoader` and the other is a local variable in function `loadLang`. In your function, the local variable of string type is getting accessed. Since `std::string` doesnt have operator[] which takes a string, you are getting error.
Naveen
Wow! I hate when that happens :\ Thanks for the help all :D
Michael S.