【发布时间】: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 << getcwd(buff) << endl;放在这个函数的顶部,看看你的进程是否在你认为的地方运行。
标签: c++ file-io static-libraries spell-checking