I am trying to read using the hex format with two characters at a time from a file. The problem is whenever the hex char has a 0 in it it is ignored while printing. ex. 08 just shows up as 8. How can I make sure it doesn't omit 0? Does it involve some kind of bit shifting?
std::ifstream stream;
stream.open(file_path, std::ios_base::binary);
if (!stream.bad()) {
std::cout << std::hex;
std::cout.width(2);
while (!stream.eof()) {
unsigned char c;
stream >> c;
cout << (short)c <<'\n';
}
}