File I/O with files sizes that are not a multiple of 8 bits

I am making a compression program, and in certain cases the resulting compressed file may not have an exact number of bytes, for example it might end up being 400 bytes and 4 bits. Here's the problem: if the c++ file I/O can only read files that are a mulitiple of 8 bits, these extra 4 bits at the end of the file will really screw up the entire decompression algorithm. Am I going to have to accommodate this, or does c++ do it for me, or really what should I do to prevent this?

P.S I'm sure you'll have noticed, but I'm new to file I/O, so nothing too too complicated please. Thanks!
Last edited on
This isn't a limitation of C++, this is a limitation of the file system. Files must land on byte boundaries.

You'll have to pad up to the next byte. No way around it.
Thank you very much. btw would you know if certain file systems need to land on, for example, 4 KB boundaries or something? When I format USBs to NTFS, it always asks me for a block size and from what I understand, would I have to pad up to this block size?
Not you, but the file system will. If you have a block size of 4 KB, a file of 4.5 KB will use two blocks, i.e. 8 KB.
Okay, thanks everyone
Topic archived. No new replies allowed.