C++ read binary file and convert to hex
问题 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; ifstream file (toread, 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(); cout << "the complete file content is in memory" << endl; std::string tohexed = ToHex(memblock, true); std::cout << tohexed << std::endl; }