How to read hex values from a file using fstream in c++?
You have to chain std::hex
when reading, the same way you chain it for writing :
infile >> std::hex >> a;
You can use the hex modifier
int n;
cin >> hex >> n;
This works:
int main()
{
const char *filename = "blah.txt";
ifstream infile(filename, fstream::in);
unsigned int a;
infile >> hex >> a;
cout << hex << a;
}