I am currently attempting to store a string containing binary code.
When I attempt to write this string to a text file it simply stores each 0 and 1 character in a string format, rather than storing it into 8 bit chunks as I require. This causes the file to be larger than intended, considering it uses 8 bits to store each 0 and 1.
Should I write the string to a .bin file instead of a .txt file? If so how would I go about doing this, and if possible an example with some working code.
My thanks for any advice in advance.
string encoded = "01010101";
ofstream myfile;
myfile.open ("encoded");
myfile << encoded;
myfile.close();
Clarification: I have a string made up of 1's and 0's(resulting from a Huffman Tree), I wish to break this string up into 8 bit chunks, I wish to write each character represented by said chink to a compressed file.