alright, so ive written my own little method of serializing a class, but im having trouble reading the strings i write to the file...
my class:
Code:
class datas
{
public:
string word[3];
int n;
int a[5];
int save(const char *filename)
{
ofstream file (filename, ios::out | ios::app | ios::binary);
if (file.is_open())
{
char buff[128];
char num[16];
itoa (n,num,2);
file.write (num, 16);
for(int i = 0; i < 3; i++)
{
char *cc = new char[word[i].size() + 1];
cc[word[i].size()] = 0;
memcpy(cc,word[i].c_str(),word[i].size());
file.write (cc, 128);
}
}
file.close();
}
int load(const char *filename)
{
ifstream rfile (filename, ios::in | ios::binary);
char rnum[16];
rfile.read (rnum, 16);
n = binti(rnum);
for(int i = 0; i < 3; i++)
{
char buff[128];
rfile.read (buff, 128);
word[i] = buff;
}
rfile.close();
}
};
it will save and load the integer easily, but im not really sure what to do with the strings...