标签:document int cst eth 组元 存储 遍历 array pdo
在MFC中有几种公共集合类来处理数组,如:CArray<int,int> m_aArray;//数组,用来存储成员,模板类
CTypePtrArray<CObArray,CStudent&> m_ptrArray;//存储指针模板类
CStringList m_strList;//字符串链表,非模板类
遍历模板类如下:
CStringList m_strList; ... POSITION pos; pos = m_strList.GetHeadPosition(); while(NULL!=pos) { ((CString)m_strList.GetNext(pos)).Empty(); } lines.RemoveAll();
添加数据:
void CEx_View::OnAdd() { UpdateData(); CEx_DocViewDoc * pDoc = GetDocument(); ASSERT_VALID(pDoc); CStudent * pStudent; pStudent = new CStudent(m_nCode,m_sName,m_lAge,m_fScore); pDoc->m_dataList.AddTail(pStudent); pDoc->curPos = pDoc->m_dataList.GetHeadPosition();//记住指针的位置 }
清空数组:
void CEx_DocViewDoc::DeleteContents() { while(!m_dataList.IsEmpty()) delete m_dataList.RemoveHead();//删除数组元素,且同时删除指针对象 CDocment::DeleteContents(); }
获取其中一个元素:
CStudent * pStudent = (CStudent*)pDoc->m_dataList.GetAt(pDoc->curPos);
标签:document int cst eth 组元 存储 遍历 array pdo
原文地址:http://blog.51cto.com/9233403/2065711