• Advertisement
Sign in to follow this  

using bitset and outputting it correctly

This topic is 3190 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <bitset>
using namespace std;
void main()
{
	ofstream file ("ValuesAndFlags.txt",ios::out|ios::binary);
	bitset<1> flag;
        char data;
        for(int i = 0;i<128;i++)
           file<<data<<flag;
        return; 
}

I want to output 9 bits of data, but I'm getting 16 bits output instead, how can I get properly output 9 bits ?

Share this post


Link to post
Share on other sites
Advertisement
Files store bytes. You can pack the information, but in the end you will have to pad the end to a multiple of 8 bits.

Share this post


Link to post
Share on other sites
Ya, ok i'll just need to make a conversion function to get bitset<8> to be a char and I'll be fine then.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement