help with fstream write function.

Hi,

I am having trouble as to understanding how the write function works.

Here is my code:

1
2
	    ofstream fo(file, ios::out | ios::binary);
	    fo.write(reinterpret_cast<char *>(&vector),sizeof(int));


And vector is

1
2
3
vector= new int [numero];
	for (int i=0; i<numero; i++){
	 vector[i]=i;


It does open the file, but with garbage inside. I have researched about this function but couldn't find a proper explanation on how to make it work.
Your reinterpret_cast is casting an int** to a char*. Remove the & sign and it will work correctly.
Yeah, it works now! Thanks!

Does it copy ALL the vector or just the first position?
Last edited on
Topic archived. No new replies allowed.