I'm reading a binary file using C++ and then trying to print the contents. Instead of printing the hex values of the file, however, it prints gibberish character representations of those numbers.
int main(int argc, char** argv)
{
std::vector<char> bios;
std::ifstream bios_stream(argv[1], std::ios::binary | std::ios::ate);
if(bios_stream.good())
{
const int bios_size = bios_stream.tellg();
bios_stream.seekg(0, std::ios_base::beg);
bios.resize(bios_size);
bios_stream.read(reinterpret_cast<char*>(bios.data()), bios_size);
bios_stream.close();
}
else {
std::cout << "Error!\n";
}
for(int i = 0; i < bios.size(); i++)
{
std::cout << std::hex << std::atoi(bios.at(i));
}
return 0;
}
Any idea how to make this print out the hex representation of the file (i.e. A0FFB126C3 etc)?