C++二进制文件中读写bitset

时间:2022-05-24 05:53:45

这个比较简单,直接上代码:

bitset< > *b = new bitset<>();
bitset< > *c = new bitset<>();
ofstream out("I:\\test.dat",ios::binary);
out.write((char *)b,);
out.close();
ifstream in("I:\\test.dat", ios::binary);
for (int i = ; i < c[].size();)
{
char temp = ;
in.read(&temp, sizeof(char));
for (int j = ; j < ; j++)
{
bool flag = (bool)((temp >> j) & );
if (flag)
c[].set(i + j);
}
i = i + ;
}
cout << "位图读取就位" << endl;
cout << c[] << endl;
in.close(); delete b;
delete c;