<分区>
有人知道 C++ 的字典 API 可以让我搜索单词并取回定义吗?
(我不介意是不是在线API,非要用JSON或者XML解析)
编辑: 抱歉,我的意思是字典中的单词定义。不是 C++ 映射。抱歉造成混淆。
<分区>
有人知道 C++ 的字典 API 可以让我搜索单词并取回定义吗?
(我不介意是不是在线API,非要用JSON或者XML解析)
编辑: 抱歉,我的意思是字典中的单词定义。不是 C++ 映射。抱歉造成混淆。
最佳答案
使用 std::map<string,string>
那么你可以这样做:
#include <map>
map["apple"] = "A tasty fruit";
map["word"] = "A group of characters that makes sense";
然后
map<char,int>::iterator it;
cout << "apple => " << mymap.find("apple")->second << endl;
cout << "word => " << mymap.find("word")->second << endl;
打印定义
关于C++ 字典 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5282779/