i have tried to write this hexdump code for dumping the contents of a tex file.

#include <iostream>
#include <fstream>
#include <string.h>

using namespace std;

int main()
  string line;
  string finline;
  char infile[100];
  char ofile[100];
  char chars[750];

  cout<<"Enter input file: ";
  cin.getline(infile, 99);
  cout<<"Enter output file: ";
  cin.getline(ofile, 99);

  ofstream out;

  ifstream file(infile);

  while(getline(file, line))
    finline += line;
    for(int i = 0; i < finline.size(); i++)
      chars[i] = finline[i];

  for(int i = 0; i < finline.size(); i++)
    chars[i] = finline[i];


  return 0;

but it only give 1 line eg. 0b3d6fc9
and not as much as i think it should.

the file contains 3 lines of data, cant think that 3 lines can be in that 1 little hex line.

Anyway please help me write 1 that will work for dumping contents of files and maby even system memory, the files one is more important at the moment.


You need to loop the chars array. Something like:

for (int i = 0; i < finline.size(); ++i) {
   cout << hex << chars[i];
This question has already been answered. Start a new discussion instead.