i found some flaws in your coding, i'll try to demonstrate each:
1- to check if the file is open, the ifstream
class has this function called is_open()
, this function returns true if a file is opened by the stream,
you should use this function instead of using ( !inFile )
2- ifstream has a function called eof()
, this function returns true if end-of-file is reached, why use this function?:
your file might contain an integer value that equals the EOF
macro, so reading this value might be interpreted as end-of-file, eof()
works the right way, and checks for a "real" end of file.
i'm not sure of what you meant with this line:
i'm just sure it's wrong, try this one to go through the entire file:
while( ! inFile.eof() )
and last, streams read at least a whole byte of data, so i'd advice for this approach:
define a char
variable that will contain the input byte.
that variable will hold an int, don't
deal with this integer as decimal, deal with it as hex.
mapping hex to string is your job, i'll just give you a hint: use logical operators ( & , | , << , >> )
, i used them in a similar project i'm working on.
3- the std function system()
was demonstrated to be insecure, check this for pausing your program:
a friend of mine wrote this program, it does exactly what yours does, but input is from console:
for more info:
one last thing, use code tags:
hope that was useful.