So it's only counting the first number from DB.txt, ie not updating the 'correct' string in the comparison if statement, and i don't understand why not, seeing as it's updating it in the cout statement.
Any ideas?
It looks to me like you are finding a valuecorrect from DBinput, and then going inputting all words into word from SPinput. When you get to the end of SPinput, you stay at the end, but then grab the next word and put it into correct. Since SPinput is still at the end, nothing will be put into word, and the inner while loop will never execute -- only the initial time. I think you need to rewind SPinput after you've looked through it.
I might try something like this.
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main(void)
{
ifstream DBinput("DB.txt");
ofstream output("Errors.txt");
string correct;
while ( DBinput >> correct )
{
ifstream SPinput("SP.txt");
int i = 0;
string word;
while ( SPinput >> word )
{
if ( correct == word )
i++;
}
cout << correct << ": " << i << endl; // for debugging
output << "There are "<< i << " matches for " << correct << "." << '\n';
}
return 0;
}
[edit]And don't use void main() .
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314