Boost logo

Boost Users :

From: Mark Wyszomierski (markww_at_[hidden])
Date: 2007-02-09 12:42:35


Thanks for all your replies. This seems to work:

    ar & (CString::PCXSTR)m_strMyCString;

that PCXSTR makes it const, I suppose.

Is it possible though to serialize a char * pointer? Because I'm
stuffing this into an std::string before serialzing, in reality, like:

    ar & std::string( (CString::PCXSTR)m_strMyCString);

not so bad writing it, but reading it back in requires 3 lines:

    std::string strTemp;
    ar & strTemp;
    m_strMyCString = strTemp.c_str();

not sure if it's possible to just do it from a const char * pointer.

Thanks,
Mark

On 2/9/07, Jeffrey McBeth <mcbeth_at_[hidden]> wrote:
> Quoting David Klein <dave_chp_at_[hidden]>:
>
> > Mark Wyszomierski wrote:
> >> One of the data types though is MFC's CString - which is just like
> >> std:string, just a wrapper around a character array. The only way to
> >> get the contents of a CString as a char array is a function called
> >> GetBuffer() which returns a non-const char pointer to the internal
> >> array. My compiler does not seem to like this, as I guess the save()
> >> function is defined as const? Is this right, and if so, is there any
> >> way I can get around this one?
> >>
> >> ar & m_3rdPartyClass.m_SomeCString.GetBuffer(); // returns non
> >> const char* !!
> >>
> >
> > I don't know how serialization for std::string is done, but it's
> > supported by
> > the library. Maybe you could create a temporary std::string from your
> > MFC string
> > and serialize that one instead? Though there may be a decrease in
> > performance
> > if you have a lot of strings to deal with.
>
> Try casting it to an LPCTSTR. That should actually be far enough for
> the Serializer to work, as that is const pointer to a TChar array, and
> TChar is simply a wchar_t or char depending on if you have Unicode
> turned on. I wouldn't put any bets on the serialized data loading
> into another app that was compiled with the opposite Unicode setting.
>
> ar & (LPCTSTR)(m_3rdPartyClass.m_SomeCString);
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net