我在使用俄语词典的拼写检查器时遇到了一些问题。问题是我的项目可以很好地处理英语,但如果我要连接俄语并尝试检查我的单词的拼写,它总是返回0(意味着没有结果)。这是我的代码(适用于英语)
char *aff = "c:\\ru_RU.aff";
char *dic = "c:\\ru_RU.dic";
Hunspell *spellObj = new Hunspell(aff,dic);
char *words = "собака"
int result = spellObj->spell(words);结果是"0“。可能是编码中的问题。我试过UTF-8,KOI8-R字典。当使用UTF-8字典时,它不能读取“单词”,当使用KOI8-R时,它的结果是0。
这太糟糕了,我不得不让它工作得很好。附注:hunspell+vs2008 c++的最新版本
发布于 2021-04-09 21:55:14
新字典通常编码为UTF-8。在MSYS2/mingw64中编译的相同示例使用新的UTF-8字典给出了正确的result=1。
// UTF-8 file "main.cpp"
#include <iostream>
#include <hunspell.hxx>
int main()
{
char *aff = "ru_RU.aff";
char *dic = "ru_RU.dic";
Hunspell *spellObj = new Hunspell(aff,dic);
char *words = "собака";
int result = spellObj->spell(words);
std::cout << "result=" << result << std::endl;
return result;
}使用了预编译包。安装时,需要进入mingw64.exe环境pacman -Su mingw-w64-x86_64-hunspell。Makefile的内容如下:
PKGS=hunspell
CFLAGS=$(shell pkg-config --cflags $(PKGS)) -std=gnu++98
LIBS=$(shell pkg-config --libs $(PKGS))
all: main
%: %.cpp
$(CXX) $(CFLAGS) -o $@ $< $(LIBS)https://stackoverflow.com/questions/16566431
复制相似问题