I\'m having some problems reading a binary file and converting it\'s bytes to hex representation.
What I\'ve tried so far:
ifstream::pos_type size;
char *memblock;
…
std::string tohexed = ToHex(memblock, true);
…
string ToHex(const string& s, bool upper_case)
There's your problem, right there. The constructor std::string::string(const char*)
interprets its input as a nul-terminated string. So, only the characters leading up to '\0'
are even passed to ToHex
. Try one of these instead:
std::string tohexed = ToHex(std::string(memblock, memblock+size), true);
std::string tohexed = ToHex(std::string(memblock, size), true);