这个比较简单,直接上代码:
bitset< 32> *b = new bitset<32>(255); bitset< 32> *c = new bitset<32>(0); ofstream out("I:\test.dat",ios::binary); out.write((char *)b,4); out.close(); ifstream in("I:\test.dat", ios::binary); for (int i = 0; i < c[0].size();) { char temp = 0; in.read(&temp, sizeof(char)); for (int j = 0; j < 8; j++) { bool flag = (bool)((temp >> j) & 1); if (flag) c[0].set(i + j); } i = i + 8; } cout << "位图读取就位" << endl; cout << c[0] << endl; in.close(); delete b; delete c;