I have a device which sends me binary data of type uint32_t. I want to save the data to a binary file. Here is my code:
#include<iostream> #include<fstream> #include <cstdlib> using namespace std; int main() { ofstream myFile ("data2.bin", ios::out | ios::binary); bool buffer[32]; for (int k = 0; k<100; k++) { for (int i = 0; i<32;i++) { buffer[i] = (bool)rand()%2; } myFile.write ((char*)&buffer, 32); } myFile.close(); } It works, but the size of the file is 3.2 kB, not 0.4 kB. Moreover, when I try to read the data from the file (the data produced by my device), I get strange outcome, not in the format described in the manual. Of course, there is more data than I expect.
What am I doing wrong?