Jump to content
  • Advertisement
Sign in to follow this  
vaneger

using bitset and outputting it correctly

This topic is 3366 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!