title: C++ stat.h incomplete type and cannot be defined
body: <p>I am having a very strange issue with stat.h</p>
  
  <p>At the top of my code, I have declarations:</p>
  
  <pre><code>#include &lt;sys\types.h&gt; 
  #include &lt;sys\stat.h&gt; 
  </code></pre>
  
  <p>And function prototype:</p>
  
  <pre><code>int FileSize(string szFileName);
  </code></pre>
  
  <p>Finally, the function itself is defined as follows:</p>
  
  <pre><code>int FileSize(string szFileName)
  {
    struct stat fileStat; 
    int err = stat( szFileName.c_str(), &amp;fileStat ); 
    if (0 != err) return 0; 
    return fileStat.st_size;
  }
  </code></pre>
  
  <p>When I attempt to compile this code, I get the error:</p>
  
  <pre><code>divide.cpp: In function 'int FileSize(std::string)':
  divide.cpp:216: error: aggregate 'stat fileStat' has incomplete type and cannot be defined
  divide.cpp:217: error: invalid use of incomplete type 'struct stat'
  divide.cpp:216: error: forward declaration of 'struct stat'
  </code></pre>
  
  <p>From this thread: <a href="https://stackoverflow.com/questions/238603/how-can-i-get-a-files-size-in-c">How can I get a file&#39;s size in C?</a>
  I think this code should work and I cannot figure out why it does not compile.  Can anybody spot what I am doing wrong?</p>