CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Location
    China
    Posts
    5

    Post how to use stl in a MFc application?

    ar didn't overload << and >> for vector ,list ,map,and so on, and these didn't inherit from Cobject, so no the virtual function Serialize, can't use the
    CTypedPtrlist.serialize(ar) to write and read ,and so on,so we lost the ways of MFC's writing and read,if we use stl in a MFC application?
    how can do this ?
    I know MFC macro max,min need be hidden if use stl.

  2. #2
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863

    Post Re: how to use stl in a MFc application?

    first of all, don't use MFC serialization, but if you are going to then just write some functions


    Code:
    template<typename T>
    CArchive& STORE_VECTOR(CArchive& ar, const std::vector<T>& t_vector)
    {
        ar << to_store.size();
        for(std::vector<T>::size_type i = 0; i < t_vector.size(); i++
            ar << t_vector[i];
        return ar;
    }
    
    template<typename T>
    CArchive& LOAD_VECTOR(CArchive& ar, std::vector<T>& t_vector)
    {
        std::vector<T>::size_type size(0);
        ar >> size;
        t_vector.resize(size);
        for(std::vector<T>::size_type i = 0; i < t_vector.size(); i++
             ar >> t_vector[i];
        return ar;
    }
    Last edited by souldog; April 28th, 2005 at 11:00 PM.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  3. #3
    Join Date
    Apr 2005
    Location
    China
    Posts
    5

    Thumbs up Re: how to use stl in a MFc application?

    Quote Originally Posted by souldog
    first of all, don't use MFC serialization, but if you are going to then just write some functions


    Code:
    template<typename T>
    CArchive& STORE_VECTOR(CArchive& ar, const std::vector<T>& t_vector)
    {
        ar << to_store.size();
        for(std::vector<T>::size_type i = 0; i < t_vector.size(); i++
            ar << t_vector[i];
        return ar;
    }
    
    template<typename T>
    CArchive& LOAD_VECTOR(CArchive& ar, std::vector<T>& t_vector)
    {
        std::vector<T>::size_type size(0);
        ar >> size;
        t_vector.resize(size);
        for(std::vector<T>::size_type i = 0; i < t_vector.size(); i++
             ar >> t_vector[i];
        return ar;
    }
    thanks!!

  4. #4
    Join Date
    Apr 2005
    Location
    China
    Posts
    5

    Question Re: how to use stl in a MFc application?

    Quote Originally Posted by souldog
    first of all, don't use MFC serialization
    This means MFC serialization is a bad structure? So MFC lost many feathers.

    How I understand this word?

    Can tell me more about MFC's serialization, how to use it, when don't use it, why we don't use it? 3x!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured