开发者

Index strings by other strings

开发者 https://www.devze.com 2022-12-25 11:54 出处:网络
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.

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)


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
0

精彩评论

暂无评论...
验证码 换一张
取 消