I encode a text file using a huffman tree. Which print out to the screen and and output to a file. File only contains the last line that prints to the console.
void traverse(string code = "") const {
string outputFile = "huffman.txt";
ofstream outfile(outputFile.c_str());
if (child0 !=NULL) {
static_cast<huffman_item<dtype> >( *child0).traverse(code + '0' );
static_cast<huffman_item<dtype> >( *child1).traverse(code + '1' );
} else{
outfile << data << freq << code << endl;
cout << " Data: " << data << " Frequency: " << freq << " Code: " << code << endl;
}
}
This is method. Can someone please help me!