The*_*GiG 23
std::map<string,string>
然后使用你可以做:
#include <map>
map["apple"] = "A tasty fruit";
map["word"] = "A group of characters that makes sense";
Run Code Online (Sandbox Code Playgroud)
然后
map<char,int>::iterator it;
cout << "apple => " << mymap.find("apple")->second << endl;
cout << "word => " << mymap.find("word")->second << endl;
Run Code Online (Sandbox Code Playgroud)
打印定义
ste*_*225 10
尝试使用std::map:
#include <map>
map<string, string> dictionary;
// adding
dictionary.insert(make_pair("foo", "bar"));
// searching
map<string, string>::iterator it = dictionary.find("foo");
if(it != dictionary.end())
cout << "Found! " << it->first << " is " << it->second << "\n";
// prints: Found! Foo is bar
Run Code Online (Sandbox Code Playgroud)