C + + Practice references-binary file browser

Source: Internet
Author: User

"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 ') &LT;&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.