Now I'm having troubles with writing the file out. I'M SO CLOSE to finishing this assignment!
OK, here is my call to the function:
Code:
case 5: cout << "Enter the name of the File to save to:" << endl;
getline(cin, nameOfFile);
entry.writeToFile(nameOfFile);
break;
Here is my function writeToFile():
Code:
void AddressBook::writeToFile(string fileName)
{
ofstream outfile;
outfile.open(fileName.c_str());
if(!outfile)
{
cout <<"Cannot write to the file" << endl;
}
addressTree->writeFile();
outfile.close();
}//end writeToFile
That function calls the following in my binary tree file:
Code:
template< typename NODETYPE >
void Tree< NODETYPE >::writeFile() const
{
ofstream out;
writeFileHelper(out, rootPtr);
}//end function writeFile
template< typename NODETYPE >
void Tree< NODETYPE >::writeFileHelper(ofstream& out, TreeNode< NODETYPE > *ptr ) const
{
ofstream outfile;
if ( ptr != 0 )
{
writeFileHelper(out, ptr->leftPtr ); // traverse left subtree
outfile << ptr->data; // process node
writeFileHelper(out, ptr->rightPtr); // traverse right subtree
} // end if
} // end function inOrderHelper
// function to perform deleteFromTree
The writeToFile worked before I changed the ifstream, but now I've been messing with it trying to get it to work. I get this error message:
:\program files\microsoft visual studio\myprojects\bst addressbook\tree.h(29) : error C2061: syntax error : identifier 'ofstream'
c:\program files\microsoft visual studio\myprojects\bst addressbook\tree.h(31) : see reference to class template instantiation 'Tree<NODETYPE>' being compiled
c:\program files\microsoft visual studio\myprojects\bst addressbook\tree.h(97) : error C2061: syntax error : identifier 'ofstream'
Error executing cl.exe.
any ideas?
This is so great, that there are people who can help. I hope I can do it at some point!
Thank you for helping.