This will do what you want... there may be a better solution.
You can use the standard library bitset template class.
The templated value is the number of bits ( 8 * sizeof(short) ) will usually
be 16.
#include <fstream>
#include <bitset>
using namespace std;
int main(int argc, char* argv[])
{
short x = 3;
bitset<(8 * sizeof(short))> aByte(x);
ofstream file("outfile.txt", std::ios::out|std::ios::trunc);
file << aByte << endl;
return 0;
}
Good Luck,
Kyle
"randy1200" <ra*******@yahoo.com> wrote in message
news:9b******************************@localhost.ta lkaboutprogramming.com...
I have the following:
short x = 3;
..
std:ofstream file(outfile.txt, std::ios::out|std::ios::trunc);
..
file << x << endl;
Of course, "3" shows up in the file. What I'd really like to see is
"00000011". I'd be very surprised to see that C++ doesn't already have an
operator to do this for me.
Thanks,
Randy