⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clist.txt

📁 MFC集合类使用说明,简单明了,通俗易懂
💻 TXT
字号:
Expand the Header Files folder, and open file StdAfx.h.
At the end of the file, type:
#include <afxtempl.h>    // MFC templates

///////////////////////////////////////////////////////////////////////////////
CList < class TYPE, class ARG_TYPE >

    TYPE        Type of object stored in the list.

    ARG_TYPE    Type used to reference objects stored in the list.
                Can be a reference.

    The CList class supports ordered lists of nonunique objects accessible
    sequentially or by value. CList lists behave like doubly-linked lists.

    ==================================================
    Class Members
    ==================================================
    AddHead
        POSITION AddHead( ARG_TYPE newElement );
        void AddHead( CList* pNewList );
    AddTail
        POSITION AddTail( ARG_TYPE newElement );
        void AddTail( CList* pNewList );
    Find
        POSITION Find( ARG_TYPE searchValue, POSITION startAfter = NULL) const;
    FindIndex
        POSITION FindIndex( int nIndex ) const;
    GetAt
        TYPE& GetAt( POSITION position );
        TYPE GetAt( POSITION position ) const;
    GetCount
        int GetCount() const;
    GetHead
        TYPE& GetHead( );      // use on either side, can be modified
        TYPE GetHead( ) const; // use only on right side, can not be modified
    GetHeadPosition
        POSITION GetHeadPosition( ) const;
    GetNext
        TYPE& GetNext( POSITION& rPosition );
        TYPE GetNext( POSITION& rPosition ) const;
    GetPrev
        TYPE& GetPrev( POSITION& rPosition );
        TYPE GetPrev( POSITION& rPosition ) const;
    GetTail
        TYPE& GetTail( );
        TYPE GetTail() const;
    GetTailPosition
        POSITION GetTailPosition( ) const;
    InsertAfter
        POSITION InsertAfter( POSITION position, ARG_TYPE newElement );
    InsertBefore
        POSITION InsertBefore( POSITION position, ARG_TYPE newElement );
    IsEmpty
        BOOL IsEmpty( ) const;
    RemoveAll
        void RemoveAll( );
    RemoveAt
        void RemoveAt( POSITION position );
    RemoveHead
        TYPE RemoveHead( );
    RemoveTail
        TYPE RemoveTail( );
    SetAt
        void SetAt( POSITION pos, ARG_TYPE newElement );

    ==================================================
    Create
    ==================================================
    CList<int, int> m_intList;
    CList<CString,CString&> m_stringList;

    ==================================================
    Insert
    ==================================================
    m_intList.AddTail(m_int);
    POSITION posTemp = m_intList.InsertBefore(pos, m_int);

    // Add three elements to the list.
    m_stringList.AddTail(CString("XYZ"));
    m_stringList.AddTail(CString("ABC"));
    m_stringList.AddTail(CString("123"));

    ==================================================
    Iterate
    ==================================================
    POSITION pos = intList.GetHeadPosition();
	while (pos != NULL)
	{
		int n = intList.GetNext(pos);
    }

    ==================================================
    Find
    ==================================================
    pos = m_intList.Find(nValue);

    // Verify the first element (index 0).
    ASSERT(CString("XYZ") == m_stringList.GetAt(m_stringList.FindIndex(0)));

    POSITION pos = m_stringList.Find(CString("XYZ"));
    ASSERT(CString("XYZ") == m_stringList.GetAt(pos));

    ==================================================
    Update
    ==================================================
    m_intList.SetAt(pos, m_int);

    // Replace CString("ABC") with CString("CBA")
    POSITION pos = m_stringList.Find(CString("ABC"));
    m_stringList.SetAt(pos, CString("CBA"));
    // Verify CString("ABC") is not in the list.
    ASSERT(m_stringList.Find(CString("ABC")) == NULL);

    ==================================================
    Delete
    ==================================================
    m_intList.RemoveAt(pos);
    m_intList.RemoveAll();

    POSITION pos = m_stringList.GetHeadPosition();
	while (pos != NULL)
	{
        delete m_stringList.GetNext(pos);
        // or use GetNext then RemoveAt(pos);
    }
    m_stringList.RemoveAll();

    ==================================================
    Serialize
    ==================================================
    m_intList.Serialize(ar);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -