本文介绍了C ++ - 使用HunSpell 1.3.2与Visual Studio 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是创建一个简单的Win32控制台应用程序,使用HunSpell拼写检查用户输入的字。
我试图关注没有改变结果。

Following the steps listed under "To use the functionality from the class library in the console application" on MSDN didn’t changed the result.

我想用这样的程序测试:

I want to test it with a program like this:

#include <iostream>
#include "HunSpell-Src/win_api/hunspelldll.h"

using namespace std;

void main()
{
    void *spellObj = hunspell_initialize("HunSpell-Dic\\en_us.aff", "HunSpell-Dic\\en_us.dic");

    char str[60];

    cin >> str;

    int result = hunspell_spell(spellObj, str);

    if(result == 0)
        cout << "Spelling error!";
    else
        cout << "Correct Spelling!";

    hunspell_uninitialize(spellObject);
}

如果我尝试编译,VS会产生以下错误消息:

VS produces the following error message if I try to compile it:

myproject\myproject\hunspell-src\win_api\hunspelldll.h(34): fatal error C1083: Cannot open include file: 'hunspell.hxx': No such file or directory

Hunspell.hxx存在于myproject \ myproject\HunSpell-Src\hunspell。 IntelliSense将#includehunspell.hxx标记为错误,而标签没有焦点时显示消息错误:无法打开源文件hunspell.hxx,但在给予焦点后,错误消失。

Hunspell.hxx is present in myproject\myproject\HunSpell-Src\hunspell. IntelliSense marks the #include "hunspell.hxx" as an error while the tab hasn’t focus with the message "Error: cannot open source file hunspell.hxx", but after giving focus to it the error disappears.

感谢您的帮助。

推荐答案

不需要预处理器定义HSPELLEDIT_DLL除非你要使用codeproject作者的自定义控件。如果要定义它(或其他预处理器定义),请参阅。

The preprocessor definition, HSPELLEDIT_DLL, is not needed unless you are going to actually use the codeproject author's custom control. In the case you want to define it (or other preprocessor definitions) refer to /D (Preprocessor Definitions).

您的路径字符串需要是双\\而不是单个\转义,并且有一些编译问题:

Your path strings need to be double \\ instead of single \ escaped and you have some compile issues:

#include <iostream>
#include "HunSpell-Src/win_api/hunspelldll.h"

using namespace std;

void main()
{
    Hunspell *spellObj = (Hunspell *)hunspell_initialize("HunSpell-Dic\\en_us.aff", "HunSpell-Dic\\en_us.dic");
//  ^change * type        ^cast returned void* to type that will be used later

    char str[60];

    cin >> str;

    int result = hunspell_spell(spellObj, str);

    if(result == 0)
        cout << "Spelling error!";
    else
        cout << "Correct Spelling!";

    hunspell_uninitialize(spellObj /*SpellObject is undefined*/);
//                        ^use correct variable
}

对于Hunspell.hxx需要告诉你的项目如何找到它。为此,打开您的项目设置和Hunspell.hxx的路径到配置属性> C ++>常规下的其他包括目录。请参阅。

For Hunspell.hxx, you need to tell your project how to find it. To do this, open your project settings and and the path to Hunspell.hxx to 'Additional Include Directories' under Configuration Properties > C++ > General. Refer to /I (Additional Include Directories).

根据 目录结构:

Based on your directory structure:


  • 您的 Project>特性>配置属性> C ++>一般> 'Additional Include Directories'应类似于: .\HunSpell-Src\hunspell;%(AdditionalIncludeDirectories)

您的 Project>属性>配置属性>接头>一般> 其他库目录应如下所示: .\Debug_dll\libhunspell;%(AdditionalLibraryDirectories)

您还需要复制 myproject\myproject\Debug_dll\libhunspell\libhunspell.dll 到您的项目输出目录(.\Debug)或您的exe将无法找到它。

You will also need to copy myproject\myproject\Debug_dll\libhunspell\libhunspell.dll to your projects output directory (.\Debug) or your exe will not be able to find it.

这篇关于C ++ - 使用HunSpell 1.3.2与Visual Studio 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 04:59