"Project-binary file Browser"
(1) do a similar binaryviewer to view the binary files of the program. After you enter a file name, you can list the contents of the file in 16-binary and ASCII-style comparisons. can participate in:
Tip: In the loop, read in 16 bytes at a time, first output in 16 binary form, and then output in character form.
[Answer]
#include <iostream>#include <iomanip>#include <fstream>#include <cstdlib>using namespace STD;intMain () {Charc[ -];Charf[ -];cout<<"Please enter a file name:";Cin>>f; Ifstream infile (f,ios::in|ios::binary);if(!infile) {Cerr<<"Open error!";Exit(1); } while(!infile.eof ()) {Infile.read (c, -);if(!infile.eof ()) { for(intI=0; i< -; ++i)cout<<setfill (' 0 ') <<SETW (2) <int((unsigned Char) (C[i])) <<" ";cout<<' \ t '; for(intI=0; i< -; ++i)cout<< (C[i]?c[i]:'. ');cout<<endl; } }return 0;}
(2) in the command line mode, enter the "command Plus file name" method by adding a parameter to the main function. will be able to display the contents of the file. Also used in the form of 16 binary and ASCII contrast.
Please refer to the file replicator that is added to the command line.
C + + Practice references-binary file browser