title: C++ binary file reading into struct
body: <p>I have written a binary file using a struct as follows:</p>
  
  <pre><code>struct block{
  char data[32];
  };
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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--;
  </code></pre>
  
  <p>and then displaying it like this:</p>
  
  <pre><code>std::cout&lt;&lt;"block 1: "&lt;&lt;blocks[0].data&lt;&lt;std::endl;
  // etc ...
  </code></pre>
  
  <p>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?</p>