I am working on a function, which is suppose to read the size of the binary file and read the data flags. The output is suppose to look something like The dataFlags are: 1 0 1 The size of the file is: 40. I got my code running, but doesn't work like it should. I can't seem to figure out what is wrong.
Cheers.
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
int getMetaData(int dataFlags[], int &dataSize)
{
ifstream binaryFile;
binaryFile.open("Data.in", ios::in|ios::binary);
if(!binaryFile)
{
cout << "The binary file data.in could not open for a binary read." << endl;
return(1);
}
else if (!binaryFile.read(reinterpret_cast<char *>(dataFlags),sizeof(int)*3))
{
cout << "The data flags could not be read." << endl;
return(1);
}
else if (!binaryFile.read(reinterpret_cast<char *>(&dataSize),sizeof(int)))
{
cout << "Could not read the size of the data. " << endl;
return(1);
}
binaryFile.close();
return 0;
}
int main()
{
int getMetaData( int dataFlags[], int dataSize);
int j;
int& dataSize = j;
int dataFlags[3];
cout << "The data flags are: " << endl;
for(int i = 0; i < 3; i++)
{
cout << dataFlags[i] << endl;
}
cout << "The size of the data is: " << dataSize << endl;
return(0);
}