I have written a binary file using a struct as follows:
struct block{
char data[32];
};
so what I end up with is basically a large binary file full of char[32]. The data is formatted in specific positions so grabbing specific pieces of information is not difficult. However, I tried to read the file like so:
int lines=0;
std::ifstream inputFile("file.bin",std::ios::binary);
while (!inputFile.eof())
{
inputFile.read(blocks[lines].data, sizeof(block));
lines++;
}
inputFile.close();
lines--;
and then displaying it like this:
std::cout<<"block 1: "<<blocks[0].data<<std::endl;
// etc ...
I thought that blocks[i].data should just give me the char[32] that belongs to index i, but it instead gives me every "data" element in the struct from that index to the end of the struct. I'm sure that it is my misunderstanding of how that works. My question is: how do I just get the char[32] represented by blocks[i].data?