closed account (3hMz8vqX)
Hi all,
for example:
it and check if it is 5E or something ...
Hope you understand...
What part are you confused about? There's lots of things you could mean and I'm not sure which it is.
closed account (3hMz8vqX)
Okay,
this is the thing...
my text file contains hexadecimal digits...
0x25
0x3A
0x5E
etc...
now in the program...
int val=0x5E
now i need to read the text file
and check if int val matches with any of the values in the text file...
I need to read the hex digits as hex digits from the text file...

http://www.cplusplus.com/reference/istream/istream/operator%3E%3E/
Line 12, specifically. You can do that same trick with a file.
closed account (3hMz8vqX)
okay one more doubt...
in the text file can i have
5E
3A
etc...
and val=3A
0x3A
0x5E
and val=0x3A
and thats it ! :)
For your actual code, there is no alternative - the C++ standard says that only literals beginning with "0x" can be considered hexadecimal. For the text file, though, you could just read the numbers as strings first, prepend "0x", and then use a stringstream to extract the hexadecimal number.
closed account (3hMz8vqX)
Thankyou very much L B:)
Im very happy:)
Regards,
Aravind
 or the text file, though, you could just read the numbers as strings first, prepend "0x", and then use a stringstream to extract the hexadecimal number.

There's no need to add the 0x prefix when reading un-prefixed hex numbers; you just need to use std::hex to set hexadecimal mode first.

Andy
Last edited on
closed account (3hMz8vqX)
Okay,
so int val=3A
is that correct?

Regards,
Aravind.
Last edited on
 so int val=3A is that correct?

No, in code you must use the 0x prefix

I was responding (unclearly, sorry) to L B's suggestion to add the prefix when reading from values from file.

Andy

PS Edited prev post to make it (hopefully) a bit clearer.
Last edited on
closed account (3hMz8vqX)
Okay,
no problem! Thankyou very much, Andy ...!
and thankyou very much L B...!
Regards,
Aravind.
Topic archived. No new replies allowed.