**编辑:除了错误指出下面,我被错误地试图编译为一个Win32项目,按照该错误代码“不是所有的控制路径返回一个值”
1> MSVCRTD .lib(crtexew.obj):错误LNK2019:无法解析的外部符号WinMain @ 16>在函数中引用_ _tmainCRTStartup 因此避免危机并完成作业。非常感谢你的帮助。希望当我知道一件或两件东西时,我可以同样向社区付钱**
在这项任务中,我们应该使用递归作为确定单词是否符合回文的技巧。尽管我仍然在努力使它成为解决问题的机制,但这段代码看起来应该是正常的。但是,编译器给我“不是所有的控制路径返回一个变量”的错误。有任何想法吗?
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
bool palcheck(string word, int first, int last);
int main()
{
ofstream palindrome, NOTpalindrome;
ifstream fin;
string word;
palindrome.open("palindrontest.txt");
NOTpalindrome.open("notPalindronetest.txt");
fin.open("input5.txt"); //list of palindromes, one per line
if (palindrome.fail() || NOTpalindrome.fail() || fin.fail())
return -1;
while (fin >> word)
{
if (palcheck(word, 0, (word.size()-1)) == true)
palindrome << word << endl;
else
NOTpalindrome << word << endl;
}
palindrome.close();
NOTpalindrome.close();
fin.close();
return 0;
}
bool palcheck(string word, int first, int last)
{
if (first >= last)
return true;
else if (word[first] == word[last])
return palcheck(word, first+1, last-1);
else// (word[first] != word[last])
return false;
}
中加入“决定”的称号(我已经删除它)取而代之,你应该接受一个答案,因为它是在这里做,所以:) – Stormenet 2011-03-21 22:03:14