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:
1 2 3
|
...
while(inFile)
...
|
i'm just sure it's wrong, try this one to go through the entire file:
1 2 3
|
...
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:
http://www.cplusplus.com/forum/beginner/103201/
a friend of mine wrote this program, it does exactly what yours does, but input is from console:
http://notes.io/ad6
for more info:
http://www.cplusplus.com/doc/tutorial/files/
one last thing, use code tags:
http://www.cplusplus.com/articles/jEywvCM9/
hope that was useful.