title: get file size with ifstream::seekg and tellg
body: <p>I have the following block to test the behaviours of the seekg and tellg when I try to get a file size:</p>
  
  <pre><code>    int size = 0;
      ifstream in(fileName.c_str(), ifstream::in | ifstream::binary);
      if(in)
      {
          in.seekg(0,ifstream::end);
          size = in.tellg();
          cout &lt;&lt; endl;
          cout &lt;&lt; endl;
          cout &lt;&lt; "********** size stream1*** =" &lt;&lt; size &lt;&lt; endl;
          in.seekg(0,ios::end);
          size = in.tellg();
          cout &lt;&lt; "********** size stream2*** =" &lt;&lt; size &lt;&lt; endl;
          in.seekg(0,ios::end);
          size = in.tellg();
          cout &lt;&lt; "********** size stream3*** =" &lt;&lt; size &lt;&lt; endl;
          in.seekg(100,ios::end);
          size = in.tellg();
          cout &lt;&lt; "********** size stream4*** =" &lt;&lt; size &lt;&lt; endl;
          in.seekg(0,ios::beg);
          size = in.tellg();
          cout &lt;&lt; "********** size stream5*** =" &lt;&lt; size &lt;&lt; endl;
          in.seekg(100);
          in.seekg(0, ios::end);
          size = in.tellg();
          cout &lt;&lt; "********** size stream6*** =" &lt;&lt; size &lt;&lt; endl;
          in.seekg(100);
          in.seekg(0, ios::cur);
          size = in.tellg();
          cout &lt;&lt; "********** size stream7*** =" &lt;&lt; size &lt;&lt; endl;
          in.seekg(-100,ios::end);
          size = in.tellg();
          cout &lt;&lt; "********** size stream8*** =" &lt;&lt; size &lt;&lt; endl;
          in.seekg(ios::beg,ios::end);
          size = in.tellg();
          cout &lt;&lt; "********** size stream9*** =" &lt;&lt; size &lt;&lt; endl;
          in.seekg(ios::beg);
          in.seekg(ios::end);
          size = in.tellg();
          cout &lt;&lt; "********** size stream10*** =" &lt;&lt; size &lt;&lt; endl;
          cout &lt;&lt; endl;
          cout &lt;&lt; endl;
      }
  </code></pre>
  
  <p>Its results are followed:</p>
  
  <pre><code>********** size stream1*** =1846
  ********** size stream2*** =1846
  ********** size stream3*** =1846
  ********** size stream4*** =1946
  ********** size stream5*** =0
  ********** size stream6*** =1846
  ********** size stream7*** =100
  ********** size stream8*** =1746
  ********** size stream9*** =1846
  ********** size stream10*** =2
  </code></pre>
  
  <p>My questions are the following:</p>
  
  <ol>
  <li>does the <strong>tellg</strong> will return the bytes the last <strong>seekg</strong> found?</li>
  <li>Why the <strong>stream5</strong> result is 0? its previous position is at the end of the file.</li>
  <li><strong>seekg</strong> will always start at beginning of the file as shown in <strong>stream5</strong>?</li>
  <li><strong>seekg</strong> cannot go backward as shown in <strong>stream5</strong>?</li>
  <li>what's the first parameter of seekg really mean? It says it is the offset of the second parameter. It seems it goes beyond the position pointed by the second parameter if it is a positive value, as showing in <strong>stream4</strong>. </li>
  <li>If I want to know the size after the first 100 bytes, I have to use the -100 as shown in <strong>stream8</strong>?</li>
  <li>why <strong>stream10</strong> is 2?</li>
  <li><strong>seekp</strong> and <strong>tellp</strong> in ofstream have the properties as <strong>seekg</strong> and <strong>tellg</strong> here?</li>
  </ol>