I'm trying to write 2 dimensional array of int type to a binary type file.
int array[3][3]={Some data};
ofstream f;
f.open("nameoffile.dat",ios::binary||ios::out);
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
f.write((char *)&array[i][j],sizeof(array));
}
}
f.close();
Above code is not complete. I only wrote a part of the code where I need help. Is this code right? It does save some data inside the file. But when I try to read it, it displays 0. Nothing else.
ifstream f;
f.open("nameoffile.dat",ios::binary||ios::in);
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
f.read((char *)&array[i][j],sizeof(array));
}
}
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
cout<<array[i][j];
}
}
f.close();
What do you think?