• Advertisement

Archived

This topic is now archived and is closed to further replies.

MFC:: CString & Serialize ::C++

This topic is 5904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello. I am very familiar with C++ STL including the containers string and stringstream. When I learned of CString and other MFC data structure and mutator when I began learning MFC from Prosise''s book (chapter 6). I am learning MFC so that I can design and implement Windows 32bit programming using C++. Ultimate, as far as textchar data is concerned, is it perferrable to use CString over C++ STL (string, vector, list, etc.)? Is it possible to have view draw character from a string object instead of a CString object? Lastly, does the default implementation for serialize work for C++ STL (string, vecto, list, etc.)? Does the STL container have to transfer data to a CString object first? One last issue involving NULL. Microsoft seems to like using NULL over ''0'', which Deitel & Deitel recommend (I highly recommend their C++ How to Program). I do not use NULL term at all in my programs. I use ''0''. When using core C++ program I have been working on into MFC, is it a necessity to change from ''0'' to NULL, bool to BOOL, true to TRUE, etc. for *all* code (even non MFC)? Thanks, Kuphryn

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by kuphryn
I am learning MFC so that I can design and implement Windows 32bit programming using C++. Ultimate, as far as textchar data is concerned, is it perferrable to use CString over C++ STL (string, vector, list, etc.)?


I like CString better, but it''s not as portable as std::string. I would not use any of the MFC containers (CMap, CArray, CList), and would stick with STL containers for these exclusively. They simply do not have the flexibility of the STL containers and are not as mature.

quote:

Is it possible to have view draw character from a string object instead of a CString object?


Certainly. DrawText takes a const char*, which you can get from either CString''s conversion operator or from string::c_str ().

quote:

Lastly, does the default implementation for serialize work for C++ STL (string, vecto, list, etc.)? Does the STL container have to transfer data to a CString object first?


There is no serialize overload for STL--serializing is an MFC thing. However, it''s not very difficult to write your own: just write out the size of the string, then the string itself.

quote:

One last issue involving NULL. Microsoft seems to like using NULL over ''0'', which Deitel & Deitel recommend (I highly recommend their C++ How to Program). I do not use NULL term at all in my programs. I use ''0''. When using core C++ program I have been working on into MFC, is it a necessity to change from ''0'' to NULL, bool to BOOL, true to TRUE, etc. for *all* code (even non MFC)?



No, these are all synonyms. You actually might get some warning trying to use true for TRUE or vice versa, but you shouldn''t have any functional problems.

Share this post


Link to post
Share on other sites
Thanks.

For serializing, I will most likely copy data from STL to CString. I am sure the process gets more complicated with data other than char inside the STL.

Kuphryn

Share this post


Link to post
Share on other sites

  • Advertisement