title: Determine the size of a binary file
body: <p>I'm trying to read a binary file and I need to determine its size, but regardless of the method I've tried, I'm getting a size of zero.</p>
  
  <p>For example:</p>
  
  <pre><code>fstream cbf(address, ios::binary | ios::in | ios::ate);
  fstream::pos_type size = cbf.tellg();                   // Returns 0.
  
  char* chunk = new char[size];
  cbf.read(chunk, size);
  //...
  </code></pre>
  
  <p>If I were to use the following:</p>
  
  <pre><code>#include &lt;sys/stat.h&gt;
  struct stat st;
  stat(address.c_str(),&amp;st);
  int size = st.st_size;
  </code></pre>
  
  <p>The size is still zero. I've also tried the following, but it's still zero.</p>
  
  <pre><code>File* fp;
  fp = open(address.c_str(), "rb");
  </code></pre>
  
  <p>How do I get the size of the file?</p>
  
  <p>Thanks for the responses... I've identified the problem:
  The binary file I was trying to access was created during the execution, and I just had forgotten to close it before trying to read from it...</p>