Hello,
I am looking for an efficient C++ technique for writing a data structure to a file and retrieving it later. To write the file, I've been doing the awkward thing of copying all my integer variables of the displayPacket class into a string class and writing it out to an ostream class with <<. For the input, I am using ifstream, but the compiler won't accept any data types besides the most basic (integer, etc).
Any suggestions?
Frank
Code:if(strcmp( (char *)myString, "save")==0) { ofstream myFile("filename.dat" ); myFile<< displayPacket.params; myFile<< displayPacket.payload; myFile.close(); } if(strcmp( (char *)myString, "open")==0) { ifstream myFile("filename.dat" ); myFile >> displayPacket.params; /*compile error: the stream does not like the string class*/ myFile >> displayPacket.payload; /*compile error: the stream does not like the string class*/ myFile >> i; /*Works for integer i*/ myFile.close;



LinkBack URL
About LinkBacks



[code] instead of <code>, and [/code] instead of </code>.