[GiNaC-list] writing symbols and expressions into binary files
Cristobal Navarro
axischire at gmail.com
Sat Jun 5 00:05:26 CEST 2010
Hello,
is it possible to write ginac symbols and expressions into a file as binary
format??
i've tried this but i get segmentation fault when printing the read
variables. you can try this one file example to see the problem.
it writes to example.dat as binary format, then reads from it as binary
format too.
//CODE
#include <ginac/ginac.h>
#include <iostream>
#include <fstream>
using namespace std;
using namespace GiNaC;
int main(){
//WRITE
if(1){
symbol a("a"), b("b");
ex myExp = a*b;
cout << "Original: Symbols are '" << a << "' and '" << b << "',
myExp = " << myExp << endl;
fstream fw;
fw.open( "example.dat", ios::out|ios::binary );
if( fw.is_open() ){
fw.write( (char*)&a, sizeof(a) );
fw.write( (char*)&b, sizeof(b) );
fw.write( (char*)&myExp, sizeof(myExp) );
fw.close();
}
else{
printf("Error Opening File for writing\n");
}
}
//READ (SHOULD NOT DEPEND OF WRITE CODE)
if(1){
symbol ca, cb;
ex copyExp;
fstream fr;
fr.open( "example.dat", ios::in|ios::binary );
if( fr.is_open() ){
fr.read( (char*)&ca, sizeof(ca) );
fr.read( (char*)&cb, sizeof(cb) );
fr.read( (char*)©Exp, sizeof(copyExp) );
fr.close();
cout << "Read from file: Symbols are '" << ca << "' and '" << cb
<< "' myExp = " << copyExp << endl;
}
else{
cout << "Error opening file for reading: does it exist?" <<
endl;
}
}
return 1;
}
//CODE
thanks in advance
--
Cristobal <http://www.youtube.com/neoideo>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cebix.net/pipermail/ginac-list/attachments/20100604/e73aa6ac/attachment.htm>
More information about the GiNaC-list
mailing list