What's the format of the encoded file?
The format is :
Header //The string "HuffEnCoded"
CharCount //Number of distinct characters in the file.
Character Table //A CharCount number of entries, each of the form
//"UCHAR Count", where UCHAR is an unsigned char and
//Count is the number of its occurrence in the
//Huffman encoded data.
Huffman Data //A stream of binary Huffman-codes of variable length.
What I have to emphasize is CharCount and Count should be
in binary form.
For example, say CharCount is 123. We know that 0x31 is the ASCII code for character "1",
0x32 is that of "2", 0x33 is that of "3". So if you save CharCount as ASCII form ( when
using << operator ), it will be "0x31","0x32","0x33". But if you save it as
binary form ( when using ostream::write() ) it will be
"0x00","0x00","0x00","0x7b", since in our system, type int is 32 bits long.
You may ask why should we adopt binary form? What the advantage?
When using ASCII, four bytes can only express value between 0 and 9999. But
when using binary form, the value can be up to 4 billion ( 2 to the power 32 ).
See some refence book about C++, the answer lies in the member function write()
and read() of the class istream and
ostream.