【问题标题】:Program says dictionary doesn't exist when it does程序说字典不存在
【发布时间】:2013-04-13 03:06:08
【问题描述】:

我正在使用我的库 libspellcheck 编写拼写检查器。我有一个向字典添加单词的功能。但是,当它确实存在时,它会不断抛出异常,说字典不存在。您可以在此处的 pastebin 上找到拼写检查器代码:http://pastebin.com/1rCFAxDz。在 libspellcheck 库中添加单词的函数如下:

void add_word(char *dict, char *word)
{
    ofstream dictionary;
    dictionary.open(dict, ios::out | ios::app); 
    if (dictionary.is_open())
    {
            dictionary << word;
            dictionary << "\n";
            dictionary.close();
    }
    else
    {
        throw 1;
    }

}

检查单词拼写的功能使用相同的字典变量,并且工作正常。我很困惑。我做错了什么?

【问题讨论】:

  • 只是为了好玩和咯咯笑,把char buff[256]; cout &lt;&lt; getcwd(buff) &lt;&lt; endl;放在这个函数的顶部,看看你的进程是否在你认为的地方运行。

标签: c++ file-io static-libraries spell-checking


【解决方案1】:

您确定您使用的路径正确吗?
喜欢:

C:\\文件夹\\文件夹\...

有时你必须使用 2 \\ 瞬间 1

【讨论】:

  • 我在 Linux 上。我使用的路径是:/usr/etc/english.dict。我使用 cat /usr/etc/english.dict 验证了它。
  • 好的,所以当你打开终端并输入: cd /usr/etc/ 它会跳转到目录?
  • 哦,顺便说一句,你不需要 ios::out,看这里:stackoverflow.com/questions/12217202/…"
  • 是的。我在我的机器上创建了目录
  • 您发布的代码没有错误,如果路径也正确我不知道是什么问题
猜你喜欢
  • 2014-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-22
  • 2013-01-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多