Great idea ... Why do not think of it before?. But it will not work: (I'm working with high-performance computing, I need a simpler way to do this. But I'll try and give some notice.
Unless you have some fancy architecture that has one bit bytes, you're going to have to work with more than one bit at a time. The C++ programming language defines the smallest amount of data it can work with to be the char, which is by (C++) definition one byte, which depends on your architecture.
Anything that appears to let you read/write/manipulate single bits is just abstracting away the work for you.
C++ also guarantees that a byte will be at least 8 bits, so you could work on an architecture with 1 bit bytes but your program will still use 8 bits per byte. Or, you could work with 12 bit bytes and your program will behave as though they were 12 bits. Hence, the "at least 8 bits".
Actually, C++ insists that a char "shall be large enough to store any member of the implementation’s
basic character set"1 - it does not insist on an 8 bit character set.
[1] ISO/IEC 14882:2003(E), Section 3.9.1 Fundamental types
I have sent Marshall an eMail about it; I'll let you know what he thinks :) He's been on the committee and all sorts, so he probably knows what he's talking about and I've overlooked something fundamental...
Assuming you are using some temporary space on the compute node for the file, then you can just mmap it. If the file is on NFS, then that's not generally a good idea.
What is the application?
If it's sharing data across nodes then I would consider using MPI instead.
If it's updating an output file, cache the writes in memory and write out the whole file every few minutes.
If it's just reading initial input and writing final output then just work in bytes and use bitwise operators to access the bits as someone suggested above.
If you do anything based on read or write, then you will be working with an array of bytes. There are no functions to access bits.
For completion, I have found one way that the C++ standard insists on an 8 bit byte minimum, but it did require going into the C standard that C++ agrees to (mostly) abide by and start digging around in <climits> and the like.
Anyway, I stand corrected. There is a guarantee that a byte will have at least 8 bits, although the implications that prove it are spread across an awful lot of paper :)