This is a small program im trying to write. A spell checker.
Anyways getting to the point. I want to know a method to read from the file and insert 1000 words from that file into a tree list. I have managed to insert one but i am not quite sure how to iterate through the file. Any help would be welcome :)
I would recommend putting the file read into the while() clause:
1 2 3 4 5
while(std::getline(fin, c))
{
// now we know that getline() succeeded
treeRoot.insert(c);
}
What you do depends on your dictionary data. The above is good if you have one word per line. If you simply separate your words with spaces then you can use this:
1 2 3 4 5
while(fin >> c)
{
// now we know that getline() succeeded
treeRoot.insert(c);
}
sorry about posting in other posts .. i just thought because they had similar problems it might be easier. Anyways thanx for the replies. The thing i dont understand is that how does it know to iterate through the file ? hmm
There is a pointer in the fstream object that marks the position of the next char to read. When getline, .get, >>, etc. is called that pointer is advanced.