Hi,
I have to use write a program in which the dictionary should be used to check whether one string is a valid word in it. Is there any dictionary library I could use? If not, how could I construct a dictionary for query?
Thanks!
Hi,
I have to use write a program in which the dictionary should be used to check whether one string is a valid word in it. Is there any dictionary library I could use? If not, how could I construct a dictionary for query?
Thanks!
If you have the list of words in a file, you could load them up in a std:map and use the find method on that.
struct Dictionary {
Dictionary() {
// load _words, here's one possible implementation:
std::ifstream input ("/usr/share/dict/words");
for (std::string line; getline(input, line);) {
_words.insert(line);
}
}
bool contains(std::string const& word) const { return _words.count(word); }
std::set<std::string> _words;
};