Basic spellchecker not working

I'm trying to create a program to read words for a file(word1.txt) and check against a dictionary (wordlist.txt) and output the number of words which match (i.e. are words). The dictionary file is formatted with each word on a new line. But the program isn't working as it only says that 1 word is ever valid however many actually valid words there are.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main ()
{

    ifstream dict;
    dict.open("wordlist.txt");
    ifstream in;
    in.open("word1.txt");
    string b;
    string a ;
    int k=0;
    while (in>>a)
    {

        while (dict>>b)
        {
            if(a==b)
            {
                k++;
            }

        }

    }
    cout << k;
}

dict >> b reads the next line everytime it is called, but what happens when you reached the end of the file? it tries to start read from the end of the file. so no words are checked...
Ah thanks. So do I need to reset the dict input each time the outer loop finishes?
when you start checking a new word from word1.txt you need to start read at the beginning of wordlist.txt
Topic archived. No new replies allowed.