I am working on File I/O. need help.

I write 20(int), 20.5(double), 10.2f(float) as Binary Mode into a file named "abc". (probably it works)
And then i got a problem with reading or getting them in their own data type..
here is code :


void KcFile::WriteInt(int a) // a = 65
{
int *p_int;
p_int = &a;
fout.write((char *)&p_int, sizeof(int));
}

int KcFile::ReadInt() // for Testing.
{
int n;

fin.read((char *)&n, sizeof(int));
cout << n << endl;

return n;
}

int main()
{
KcFile kcfile;
// ofstream.open and check that it work by using ofstream.Is_open()
kcfile.WriteInt(65);
// ofstream.close();
//ifstream.open and check.
kcfile.ReadInt();
// close();
}

I don't know and understand .. plz help me T_T
Thatnks in advance.
p_int is already a pointer, don't take the address again when you write to the file or you will write the address to the file.
Topic archived. No new replies allowed.