How to read hex values from a file using fstream in c++? -
as title says, how read hex values using fstream?
i have code: (let's have "ff" in file.)
fstream infile; infile.open(filename, fstream::in|fstream::out|fstream::app); int a; infile >> std::hex; infile >> a; cout << hex << a; but not give me output instead of ff. know there fscanf(fp, "%x", val) curious there way using stream library.
update:
my code right along, turns out error couldn't read "fff" , put in variable a,b,c this
while (infile >> hex >> >> b >> c) { cout << hex << << b << c << "\n"; } can me this? have separate every hex values want read space? because infile >> hex >> setw(1) doesn't work..
you can use hex modifier
int n; cin >> hex >> n;
Comments
Post a Comment