I need to read a file and insert each word into a binary search tree. I'm halfway there but I'm a little stumped. It opens the file just fine but then how to get each separate word into its own node is beyond me. Here is what I have. It's half code and half pseudo code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
if(inFile.is_open())
{
while(getline(inFile,lineFile))//inFile: file //lineFile: line in file
{
//convert text in file to lower case
toLowerCase(lineFile);
//get each word into a node in a bst
binaryTree.insert(word);
}
}
else cout << "Unable to open file";
inFile.close();
That works great, thanks. However, as it iterates through several documents, I get a segmentation fault halfway through the second one. I can't figure what is causing it. If you need to see more code than what I have originally posted, let me know.