C++常用库函数
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MFC数组类
CByteArray:
CDWordArray:
CPtrArray:
CUIntArray:
CWordArray:
CStringArray:
常用成员函数
1.int Add(ARG_TYPE newElement ); throw(CMemoryException );
2.TYPE& ElementAt(int nIndex );
3.void FreeExtra();
4.TYPE GetAt(int nIndex )const
5.int GetSize()const;
6.int GetUpperBound()const;
7.(1)void InsertAt(int nIndex, ARG_TYPE newElement, int nCount = 1 );
throw(CMemoryException );
(2)void InsertAt(int nStartIndex, CArray* pNewArray );
throw(CMemoryException );
8.void RemoveAll();
9.void SetAt(int nIndex, ARG_TYPE newElement );
10.void SetAtGrow(int nIndex, ARG_TYPE newElement ); throw(CMemoryException ); 11.void SetSize(int nNewSize, int nGrowBy = -1 ); throw(CMemoryException );
例:
CStringArray m_strArray
m_strArray.SetSize(5,5);
m_strArray[0] = "111111111111";
m_strArray[2] = "333333333333";
m_strArray[4] = "555555555555";
增加元素
int m_nIndex = 0;
CString m_strValue = "Default";
int m_nRadio = 0;
if (m_nRadio == 0)
m_strArray.SetAtGrow(m_nIndex, m_strValue);
else if (m_nRadio == 1)
m_strArray.Add(m_strValue);
else
m_strArray.InsertAt(m_nIndex, m_strValue, 1);
删除
int m_nIndex= 0;
m_strArray.RemoveAt(m_nIndex);
MFC的链表类
模板类Clist CTypedPtrList
非模板类CObList CPtrList CStringList
MFC链表类的常用成员函数——以Clist为例
1.CList(int nBlockSize = 10 );
2.TYPE GetHead()const;
3.TYPE GetTail()const;
4.RemoveHead()
5.RemoveTail()
6.原型1:POSITION AddHead(ARG_TYPE newElement );
原型2:void AddHead(CList* pNewList );
7.原型1:POSITION AddTail(ARG_TYPE newElement );
原型2:void AddTail(CList* pNewList );
8.RemoveAll()
9.POSITION GetHeadPosition()const;
10.POSITION GetTailPosition()const;
11.TYPE GetNext(POSITION& rPosition )const;
12.TYPE GetPrev(POSITION& rPosition )const;
13.TYPE GetAt(POSITION position )const;
14.void SetAt(POSITION pos, ARG_TYPE newElement );
15.void RemoveAt(POSITION position );
16.POSITION InsertBefore(POSITION position, ARG_TYPE newElement ); 17.POSITION InsertAfter(POSITION position, ARG_TYPE newElement ); 18.POSITION Find(ARG_TYPE searchValue, POSITION startAfter = NULL)const; 19.POSITION FindIndex(int nIndex )const;
20.int GetCount()const;
21.BOOL IsEmpty()const;
例题
struct CStudent
{
CString m_strName;
int m_nScore;
};
CPtrList m_List;
向添加链表中添加元素
CStudent* m_pStudent = new CStudent;
m_pStudent->m_strName = m_strName;
m_pStudent->m_nScore = m_nScore;
m_List.AddTail(m_pStudent);
删除节点
int nNumber;
CStudent* m_pStudent = NULL;
if (m_List.IsEmpty())
MessageBox("结点已经全部删除!";