Does anyone know of a dictionary API for C++ that allows me to search for a word and get back the definition?
(I don't mind if it is an online API and I have to use JSON or XML to parse it)
Edit: Sorry, I meant a dictionary as in definitions for words. Not a C++ Map. Sorry for confusion.
Use std::map<string,string>
then you can do:
#include <map>
map["apple"] = "A tasty fruit";
map["word"] = "A group of characters that makes sense";
and then
map<char,int>::iterator it;
cout << "apple => " << mymap.find("apple")->second << endl;
cout << "word => " << mymap.find("word")->second << endl;
to print the definitions
Try using the 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With