C++二进制文件中读写bitset
这个比较简单,直接上代码:
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;
posted on 2015-05-09 15:44 Wonder奇迹奇迹 阅读(1314) 评论(0) 编辑 收藏 举报