c++ - C++中的字典库

标签 c++

我必须使用编写一个程序,其中应该使用字典来检查一个字符串是否是其中的有效单词。有没有我可以使用的词典库?如果没有,我如何构建字典进行查询?

谢谢!

最佳答案

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/

相关文章:

C++ 堆损坏但仅在单元测试项目中

c++ - 为什么 = 运算符被删除,我该如何解决它?

C++ 函数参数和类

c++ - 打印作业时,最后的作业状态是 JOB_STATUS_RETAINED,而不是 JOB_STATUS_PRINTED

c++ - 是否添加到 "char *"指针 UB,但它实际上并不指向 char 数组?

c++ - OpenCv 2.3 C - 如何隔离图像中的对象

c++ - 如何从表示 usec 时间的 32 位 int 转换为表示时间的 32 位 int(以秒为单位的二进制分数)?

c++ - 更改编码后项目未构建

c++ - static 和 const 变量有什么区别?

c++ - 需要 C++ 中非常通用的 argmax 函数