Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transferring contents of array of 8-bit bitsets to an array of bool

Status
Not open for further replies.

drrep

Programmer
Mar 13, 2002
47
US
Hi,

I am handling bits with the STL bitset class. My code sets up an array of 8-bit bitsets, the byte data coming from a file.

The following is the code I am using....now, how can I get the contents of my array of 8-bit bitsets into an array of boolean since the content is either 0 or 1?

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <bitset>
#include <fstream>


using namespace std;

typedef vector<bitset<8> > bitarray;

void Dummy()
{

bitarray::iterator numbits;
unsigned long ul;



// Read binary file back into a new bitset array
bitarray inbits;

ifstream fp(&quot;C:\\test.bin&quot;,ios_base::binary);

while(fp.good())
{
ul = fp.get();
if (fp.good())
inbits.push_back(bitset<8>(ul));
}

// Print out bitset array again as char 0,1
for (numbits = inbits.begin(); numbits!=inbits.end (); numbits++)
{
cout << *numbits << endl;

}


}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top