我必须使用编写一个程序,其中应该使用字典来检查一个字符串是否是其中的有效单词。有没有我可以使用的词典库?如果没有,我如何构建字典进行查询?
谢谢!
最佳答案
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;
};
关于c++ - C++中的字典库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2211097/