Dictionary Library in C ++

I need to write a program in which a dictionary should be used to check if one line is a valid word in it. Is there a dictionary library that I could use? If not, how can I build a dictionary for the query?

Thank!

+3
source share
4 answers
struct Dictionary {
  Dictionary() {
    // load _words, here 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;
};
+8
source

Try using the STL set or map to save your words. Regarding getting a list of words, Google is likely to help you.

+4
source

, std: map find.

+2
0
source

Source: https://habr.com/ru/post/1731625/


All Articles