This has me pretty bothered as I should be able to do it but when I read in the hex number and assign it to an unsigned int when I print it out I get a different number. Any advice would be great. Thanks
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream myfile;
myfile.open("test.text");
unsigned int tester;
string test;
myfile >> hex >> tester;
cout << tester;
system("pause");
return 0;
}
I bet you don’t get a “different number”.
I bet you get the same value, but in decimal representation.
You’re already extracting a hex-representation value (
myfile >> hex >> tester); now insert one, too (cout << hex << tester)!