Read binary file passed in from command line

I need to pass a file from the command line, read the [binary] contents, output to console, and create an output file. I have not added the create file section.

#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;

int main()
{
//variable for file being read in.
//prompt for file name and open the file
char fileName[50];
ifstream inFile;
int size=0;
cout << "Enter file to be read" << endl;
cin.getline(fileName, 50);
inFile.open(inFile, ios::in|ios::binary);
inFile.seekg(0, ios::end);
size = (int) inFile.tellg();
inFile.seekg(0, ios::beg);

if(!inFile.is_open())
{
exit(EXIT_FAILURE);
}

char binData[50];
inFile >> binData;
while(inFile.tellg() < size)
{
inFile.read(char);
cout << binData << " ";
inFile >> binData;
}

return 0;
}
There's a fairly good explanation here (also see the next page). They're the last too pages in a very good tutorial on C.
https://computer.howstuffworks.com/c38.htm
Topic archived. No new replies allowed.