由于某种原因,fstream 流仅从二进制文件中每隔一个字节读取一次。为什么会这样?
std::ifstream file("../data/data.BIT", std::ifstream::in | std::ifstream::binary);
unsigned char current_bite;
const int number_of_bits = 8;
int step = 0;
while (file >> current_bite) {
file.read((char*)¤t_bite, sizeof(current_bite));
std::bitset<8>buffer(current_bite);
for (int i = 0; i < number_of_bits; ++i) {
bit_buffer.emplace_back(buffer[i]);
std::cout << buffer[i] << ' ';
}
std::cout << "byte number = " << step <<'\n';
step++;
if (step == 39) {
break;
}
}
file.close();
std::cout << bit_buffer.size();