Hi. I've been trying to read a file byte by byte into a .txt file and then reproduce the original file back from the .txt file. For this
I want to include ALL characters(even white spaces).
Also I don't want that extra character hanging on at the end of the file.
I've tried this.
ifstream fin ("file.txt", ios::binary); // Opens a file in binary mode
ifstream::pos_type size = fin.tellg(); // This is the size (in bytes of the file)
char* memblock = newchar [size]; // Create a memory block that will hold the data
fin.read(memblock, size); // Read from the file to the memory block.
Then to write it again:
1 2
ofstream fout("bytesequence.txt", ios::binary); // Opens a file
fout.write(memblock, size); // Writes the data.