<span style="color: black;"></span>Hello,<br><br>is it possible to write ginac symbols and expressions into a file as binary format??<br>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.<br>
it writes to example.dat as binary format, then reads from it as binary format too.<br><br>//CODE<br>#include <ginac/ginac.h><br>#include <iostream><br>#include <fstream><br><br>using namespace std;<br>
using namespace GiNaC;<br>
int main(){<br><br> //WRITE<br> if(1){<br> symbol a("a"), b("b");<br> ex myExp = a*b;<br> cout << "Original: Symbols are '" << a << "' and '" << b << "', myExp = " << myExp << endl;<br>
fstream fw;<br> fw.open( "example.dat", ios::out|ios::binary );<br> if( fw.is_open() ){<br> fw.write( (char*)&a, sizeof(a) );<br> fw.write( (char*)&b, sizeof(b) );<br>
fw.write( (char*)&myExp, sizeof(myExp) );<br> fw.close();<br> }<br> else{<br> printf("Error Opening File for writing\n");<br> }<br> }<br> //READ (SHOULD NOT DEPEND OF WRITE CODE)<br>
if(1){<br> symbol ca, cb;<br> ex copyExp;<br> fstream fr;<br> fr.open( "example.dat", ios::in|ios::binary );<br> if( fr.is_open() ){<br> fr.read( (char*)&ca, sizeof(ca) );<br>
fr.read( (char*)&cb, sizeof(cb) );<br> fr.read( (char*)&copyExp, sizeof(copyExp) );<br> fr.close();<br> cout << "Read from file: Symbols are '" << ca << "' and '" << cb << "' myExp = " << copyExp << endl;<br>
}<br> else{<br> cout << "Error opening file for reading: does it exist?" << endl;<br> }<br> }<br> return 1;<br>}<br>//CODE<br>thanks in advance<br><span style="color: black;"><div dir="ltr">
<div>
--<br><a href="http://www.youtube.com/neoideo" target="_blank">Cristobal</a></div></div></span><br>