scenario is the operation of
a Huffman coding tree. The so-called Huffman coding is to re-encode the characters in the text with 0 and 1 in a certain way, in which more characters use fewer digits. For example, the letter e appears a lot in this text, and the encoding assigned to it may be 01, while the letter s appears less, and the encoding for it may be 011110.
because I can"t read and write bit to the file directly (recommended if there is a way or a mature library), so we have to store all the characters of the file into 0 or 1 in a string, and then store every 8 characters in the string. Because these eight characters are all made up of 01, if you treat this paragraph as a binary number, you can get a number between 0 and 255. then convert this number to char and then output it to a file..
then the problem arises, and now I"m going to read my output from this file (obviously it will be a lot of garbled code if I look at it directly).
it doesn"t matter whether it"s garbled or not. Anyway, I read it and put it in a string, and then each character corresponds to a number of 0-255. then I turn this number back to the binary string and put it together, so I get the Huffman code again. It turns out that I can"t go back to this step.
my personal idea is that maybe when I read it, cPP looks confused and doesn"t know what kind of coding it is going to follow and what J8 stuff it is reading, so what I read back is wrong. If you can tell cPP, you can read it according to the character 8bit. You don"t need to worry about what exactly is read in. I think it can solve this problem, right?
Thank you