could someone tell me what is wrong with this code?
Out_file = new ofstream("ABC.dat", std::ios::binary);
for (int i = 0; i < Elem->entries(); i++)
{
co_ord_X = (*Elem)[i]->Getx(); co_ord_Y = (*Elem)[i]->Gety(); co_ord_Z = (*Elem)[i]->Getz();
Intensity = (*Elem)[i]->GetInt();
ofstream out_txt( "z2_out.txt",ios::app);
out_txt<<co_ord_X<<" "<<co_ord_Y<<" "<<co_ord_Z <<" "<<Intensity<<endl;
out_txt.close();
Out_file->write(reinterpret_cast<char*>(&co_ord_X), sizeof(double));
Out_file->write(reinterpret_cast<char*>(&co_ord_Y), sizeof(double));
Out_file->write(reinterpret_cast<char*>(&co_ord_Z), sizeof(double));
Out_file->write(reinterpret_cast<char*>(&Intensity), sizeof(double));
}
The variable Elem is a pointer to an Array. co_ord_X, co_ord_y, co_ord_y and Intensity are of type double. I am able to output the text file ("out_txt"), however I have problems writing the binary ("Out_file"). The strange thing is that under some circumstances it works (depending on the values of the variables co_ord_X, co_ord_y, co_ord_y and Intensity) and in other cases, it doesn't. Can someone please tell me what is wrong? Driving me crazy.
Regards, Charles.