| Line | |
|---|
| 1 |
|
|---|
| 2 | // reading a complete binary file
|
|---|
| 3 | #include <iostream>
|
|---|
| 4 | #include <fstream>
|
|---|
| 5 | #include <stdint.h>
|
|---|
| 6 | #include <stdio.h>
|
|---|
| 7 | using namespace std;
|
|---|
| 8 |
|
|---|
| 9 | ifstream::pos_type size;
|
|---|
| 10 | char * memblock;
|
|---|
| 11 |
|
|---|
| 12 | char c1,c2;
|
|---|
| 13 |
|
|---|
| 14 | int main (int argc, char * argv[]) {
|
|---|
| 15 |
|
|---|
| 16 | ifstream in1 ( argv[1], ios::in|ios::binary);
|
|---|
| 17 | ifstream in2 ( argv[2], ios::in|ios::binary);
|
|---|
| 18 |
|
|---|
| 19 | if (in1.is_open() && in2.is_open())
|
|---|
| 20 | {
|
|---|
| 21 | long begin,end;
|
|---|
| 22 | begin = in1.tellg();
|
|---|
| 23 | in1.seekg (0, ios::end);
|
|---|
| 24 | end = in1.tellg();
|
|---|
| 25 | in1.seekg (0, ios::beg);
|
|---|
| 26 | cout << argv[1] <<" size:" << end-begin << endl;
|
|---|
| 27 |
|
|---|
| 28 | begin = in2.tellg();
|
|---|
| 29 | in2.seekg (0, ios::end);
|
|---|
| 30 | end = in2.tellg();
|
|---|
| 31 | in2.seekg (0, ios::beg);
|
|---|
| 32 | cout << argv[2] <<" size:" << end-begin << endl;
|
|---|
| 33 |
|
|---|
| 34 | while ( in1.good() && in2.good() )
|
|---|
| 35 | {
|
|---|
| 36 | c1 = in1.get();
|
|---|
| 37 | c2 = in2.get();
|
|---|
| 38 | if (c1 != c2)
|
|---|
| 39 | {
|
|---|
| 40 | cout << "difference found @ adress:" << hex << in1.tellg() << "\t" << in2.tellg() << endl;
|
|---|
| 41 | printf ("%30s \t: 0x%X \n", argv[1] ,uint8_t(c1) );
|
|---|
| 42 | printf ("%30s \t: 0x%X \n", argv[2] ,uint8_t(c2) );
|
|---|
| 43 | break;
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | in1.close();
|
|---|
| 48 | in2.close();
|
|---|
| 49 | } //end of if file open
|
|---|
| 50 |
|
|---|
| 51 | return 0;
|
|---|
| 52 | } //end of main
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.