I get the right text when not in unicode but the wrong text in unicode. On unicode it saves right but what I get is not the text on the file.
This is what i use to save and load from a file:
Save:
Code: Select all
class Serializer
{
public:
Serializer (wxString const & nameFile) : _stream(nameFile)
{
if (!_stream.IsOpened ())
throw "couldn't open file";
}
...
void PutString (wxString const & str)
{
int len = str.length ();
PutLong (len);
if(!_stream.Write (str, wxConvUTF8))
throw "file write failed";
}
bool Commit() {
return _stream.Commit();
}
private:
wxTempFile _stream;
};
Code: Select all
class DeSerializer
{
public:
DeSerializer (wxString const & nameFile) : _stream(nameFile) {
if (!wxFile::Exists(nameFile))
throw "File doesn't exist";
if (!_stream.IsOpened())
throw "couldn't open file";
}
...
wxString GetString ()
{
long len = GetLong ();
long e;
wxString str;
str.resize(len);
e = _stream.Read (&str [0], len);
if (e != len)
throw "file read failed";
return str;
}
private:
wxFile _stream;
};
The line: e = _stream.Read (&str [0], len); gets the wrong text.
What am I doing wrong?