Parse file to hex
<p>Assume that I have a file .img. I want to parse the file and display it by hex. This is my code reference in the internet. But the application display is null. Please help me to resolve it.</p>

<pre><code>     int _tmain(int argc, _TCHAR* argv[])
      {
    const char *filename = "test.img";
    ifstream::pos_type size;
    char * memblock;
    ifstream file(filename, ios::in|ios::binary|ios::ate);
      if (file.is_open())
      {
        size = file.tellg();
        memblock = new char [size];
        file.seekg (0, ios::beg);
        file.read (memblock, size);
        file.close();

        std::string tohexed = ToHex(std::string(memblock, size), true);
        cout &lt;&lt; tohexed &lt;&lt; endl;
      }
      }


        string ToHex(const string&amp; s, bool upper_case)  { 


    ostringstream ret;

    for (string::size_type i = 0; i &lt; s.length(); ++i)
    {
        int z = (int)s[i];
        ret &lt;&lt; std::hex &lt;&lt; std::setfill('0') &lt;&lt; std::setw(2) &lt;&lt; (upper_case ? std::uppercase : std::nouppercase) &lt;&lt; z;
    }

    return ret.str();
}
</code></pre>
