+ 5

how can I create my own data type which can take only hexadecimal in input??

I wanted to know if it's possible and if it's possible then how can I do it...??

30th Sep 2017, 3:51 AM
Omkar Tripathi
Omkar Tripathi - avatar
4 Answers
+ 6
* Create a class * Take a string in constructors parameters * If the string is not in hex, throw an exception http://forums.codeguru.com/showthread.php?470704-Is-there-a-function-that-tell-you-whether-a-string-is-HEX-number
30th Sep 2017, 4:05 AM
Rrestoring faith
Rrestoring faith - avatar
+ 4
Using a custom class, this is possible. You will have to overload the >> operator to read a string (since FF is also a Number), and then convert it into a number for storage using stol or a similar function...
30th Sep 2017, 4:10 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
@ Kinshuk Vasisht.. Can u write the code needed..
30th Sep 2017, 11:47 AM
Omkar Tripathi
Omkar Tripathi - avatar
+ 2
https://code.sololearn.com/c2SGMjkCimz2/?ref=app Try if this is what you wanted. Ill change if it didn't work for you..
30th Sep 2017, 5:10 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar