Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ dictionary API [closed]

Tags:

c++

api

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.

like image 367
Tom Leese Avatar asked Nov 27 '22 01:11

Tom Leese


2 Answers

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

like image 165
The GiG Avatar answered Dec 06 '22 18:12

The GiG


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
like image 31
steveo225 Avatar answered Dec 06 '22 18:12

steveo225