title: Using Struct Stat()
body: <p>I'm trying to figure out how exactly to use stat() to capture information about a file.  What I need is to be able to print several fields of information about a file.  So..</p>
  
  <pre><code> #include &lt;iostream&gt;
   #include &lt;sys/types.h&gt;
   #include &lt;sys/stat.h&gt;
   #include &lt;fcntl.h&gt;
   using namespace std;
  
   int main() {
       struct stat buf;
       stat("file",&amp;buf);
                 ...
       cout &lt;&lt; st_dev &lt;&lt; endl;
       cout &lt;&lt; st_ino &lt;&lt; endl;
       cout &lt;&lt; st_mode &lt;&lt; endl;
       cout &lt;&lt; st_nlink &lt;&lt; endl;
       cout &lt;&lt; st_uid &lt;&lt; endl;
       cout &lt;&lt; st_gid &lt;&lt; endl;
       cout &lt;&lt; st_rdev &lt;&lt; endl;
       cout &lt;&lt; st_size &lt;&lt; endl;
       cout &lt;&lt; st_blksize &lt;&lt; endl;
       cout &lt;&lt; st_blocks &lt;&lt; endl;
       cout &lt;&lt; st_atime &lt;&lt; endl;
       cout &lt;&lt; st_mtime &lt;&lt; endl;
       cout &lt;&lt; st_ctime &lt;&lt; endl;
       ...
   }
  </code></pre>
  
  <p>I'm thoroughly confused about how to do this.  Why is &amp;buf a parameter to stat?  I don't care about storing this information in memory, I just need the outputted fields within my c++ program.  How do I access the information contained in the struct?  Is buf actually supposed to contain the returned information from stat()?</p>