I am trying to serialize several text files and I have a function like this:
void to_file_px(Ciphertext* encryptedPx, int index) {
// Serialize Pixel i
//red
filebuf* fbCipherR; // EDIT: THIS LINE IS PROBLEMATIC
string* filenameR = new string("../serialization/pixels/px" + to_string(index) + "R.txt");
fbCipherR -> open((*filenameR).c_str(), std::ios::out|std::ios::binary);
ostream* osCipherR = new ostream(fbCipherR);
encryptedPx[0].Ciphertext::save((*osCipherR));
fbCipherR -> close();
delete filenameR;
delete fbCipherR;
delete osCipherR;
//green
//blue
delete[] encryptedPx;
}
However, this function causes an error as Segmentation fault (core dumped)
.
May I know what exactly causes the error?
Note: Ciphertext::save
comes from Microsoft SEAL
OK, I made a mistake. I didn't initialize filebuf*
.
So I changed filebuf* fbCipherR = new filebuf();
and I got a new error message:
terminate called after throwing an instance of 'std::runtime_error'
what(): I/O error
Aborted (core dumped)