title: ifstream:: What is the maximum file size that a ifstream can read
body: <p>I tried to read a 3GB data file using ifstream and it gives me wrong file size, whereas when I read a 600MB file, it gives me the correct result.  In addition to wrong file size, I am also unable to read the entire file using ifstream.</p>
  
  <p>Here is the code that I used</p>
  
  <pre><code>        std::wstring name;
          name.assign(fileName.begin(), fileName.end());
          __stat64 buf;
          if (_wstat64(name.c_str(), &amp;buf) != 0)
              std::cout &lt;&lt; -1; // error, could use errno to find out more
  
          std::cout &lt;&lt; " Windows file size : " &lt;&lt; buf.st_size &lt;&lt; std::endl;;
  
  
          std::ifstream fs(fileName.c_str(), std::ifstream::in | std::ifstream::binary);
          fs.seekg(0, std::ios_base::end);
  
          std::cout &lt;&lt; " ifstream  file size: " &lt;&lt; fs.tellg() &lt;&lt; std::endl;
  </code></pre>
  
  <p>The output for 3GB file was </p>
  
  <pre><code> Windows file size : 3147046042
   ifstream  file size: -1147921254
  </code></pre>
  
  <p>Whereas the output for 600 MB file was</p>
  
  <pre><code> Windows file size : 678761111
   ifstream  file size: 678761111
  </code></pre>
  
  <p>Just in case, I also tested for 5GB file and 300 MB file,</p>
  
  <p>The output for 5GB file was </p>
  
  <pre><code>Windows file size : 5430386900
   ifstream  file size: 1135419604
  </code></pre>
  
  <p>The output for 300MB file was </p>
  
  <pre><code>Windows file size : 318763632
   ifstream  file size: 318763632
  </code></pre>
  
  <p>It looks to me like it is reaching some limit.</p>
  
  <p>I am testing the code using Visual Studio 2010 on a Windows Machine which has plenty of memory and disk space.</p>
  
  <p>I am trying to read some large files. Which is a good stream reader to use if ifstream can't read large files?</p>