其他字符串的索引字符串

Mic*_* S. 2 c++ string indexing unordered-map tr1

我需要用其他字符串索引特定的字符串,我真的找不到一个好方法.我试图使用tr1 :: unordered_map,但我在使用它时遇到了一些困难.如果有人能告诉我最好的方法是什么,我真的很感激:)我还需要用数字索引对象(数字不按顺序,所以我不能使用向量)

Ale*_*ski 7

那么std :: map怎么样?

std::map<std::string, std::string> foo;
Run Code Online (Sandbox Code Playgroud)

然后你可以添加元素,

foo["bar"] = "baz";
cout << foo["bar"] << std::endl;  // baz
Run Code Online (Sandbox Code Playgroud)