所以我无法从document1中抓取一个单词并将它与document2中的单词列表进行比较。因此,当我运行该程序时,document1的第一个单词与document2的单词列表进行比较,但document1中的下一个单词不与document2中的列表进行比较。我不确定问题是什么......它与.eof()函数有关吗?如何将文件中的单词与另一个文件中的单词列表进行比较以用于C++?
string typedString, actualString, document1 = "A.txt", document2 = "Dictionary.txt";
ifstream observeDoc, actualDoc;
observeDoc.open(document1);
actualDoc.open(document2);
while (observeDoc.is_open())
{
while (true)
{
observeDoc >> typedString;
if (observeDoc.eof()) break;
cout << typedString << endl;
while (true)
{
actualDoc >> actualString;
if (actualDoc.eof())
{
actualDoc.open(document1);
break;
}
cout << '\t' << actualString << endl;
}
}
if (observeDoc.eof()) break;
}
observeDoc.close();
actualDoc.close();
OUTPUT:
我看不到在这个代码中的列表或比较。 – Barry 2014-10-30 17:43:06