title: Read and display all file bytes in C++
body: <p>I'm trying to show all the bytes in a .DAT file. I'm completely new to programming and I managed to find how to display the file size correctly but every output byte that I get are 0s even if in HxD the bytes aren't all zero.</p>
  
  <p>What I get:</p>
  
  <pre><code>size is: 11
  0000000000000000000000
  </code></pre>
  
  <p>What I should get:</p>
  
  <pre><code>size is: 11
  48656C6C6F20776F726C64
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  #include &lt;fstream&gt;
  #include &lt;iterator&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  int main () {
    //open file and get size
    streampos begin,end;
    ifstream myfile ("TRPTRANS.DAT", ios::binary);
    begin = myfile.tellg();
    myfile.seekg (0, ios::end);
    end = myfile.tellg();
    int n;
    n=(end-begin);
    cout &lt;&lt; "size is: " &lt;&lt; n&lt;&lt;endl;
  
    //read file
    vector&lt;char&gt; randomBytes(n);
    myfile.read(&amp;randomBytes[0], n);
  
    //display bytes
    for (auto&amp; el : randomBytes)
    cout &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; hex &lt;&lt; (0xff &amp; (unsigned int)el);
    cout &lt;&lt; '\n';
  
    return 0;
  }
  </code></pre>
  
  <p>Can someone help me fix this and show the bytes correctly thanks</p>