Meta Data

Hello,

I'am new to programming, and currently working on a getMetaData function that is suppose to tell you the size of the data and the data Flags that are stored in a binary file. I can get the function to run, but it doesn't display the info. correctly. I am stumped, and not sure what to do. If anyone could give me some hints that would be great.

Cheers.



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

using namespace std;


int getMetaData(int dataFlags[], int *dataSize)
{

ifstream binaryFile("data.in", ios::in | ios::binary);

if(!binaryFile)
{
cout << "Could not open file for binary read" << endl;
return (1);
}
else if(!binaryFile.read(reinterpret_cast<char *>(dataFlags), sizeof(int)*3))
{
cout << "Could not read data flags from the binary file" << endl;
return(1);
}
else if(!binaryFile.read(reinterpret_cast<char *>(&dataSize), sizeof(int)))
{
cout << "Could not read data size from the binary file" << endl;
return (1);

}
binaryFile.close();

system("pause");

return (0);
}

int main()

{

int *dataSize = 0;
int dataFlags[3];

getMetaData(dataFlags, dataSize);

cout << "The data Flags are: "<< endl;

for(int i = 0; i < 3; i++)
{
cout << dataFlags[i] << endl;
}
cout <<" The size of the data in bytes is: " << dataSize << endl;

system("Pause");

return 0;
}
Try passing a reference to read:
binaryFile.read(reinterpret_cast<char *>(&dataFlags), sizeof(int)*3)
Topic archived. No new replies allowed.