CStringList Class

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at CStringList Class.

Supports lists of CString objects.

class CStringList : public CObject  

The member functions of CStringList are similar to the member functions of class CObList. Because of this similarity, you can use the CObList reference documentation for member function specifics. Wherever you see a CObject pointer as a return value, substitute a CString (not a CString pointer). Wherever you see a CObject pointer as a function parameter, substitute an LPCTSTR.

CObject*& CObList::GetHead() const;

for example, translates to

CString& CStringList::GetHead() const;

and

POSITION AddHead( CObject* <newElement> );

translates to

POSITION AddHead( LPCTSTR <newElement> );

Public Constructors

NameDescription
CObList::CObListConstructs an empty list.

Public Methods

NameDescription
CObList::AddHeadAdds an element (or all the elements in another list) to the head of the list (makes a new head).
CObList::AddTailAdds an element (or all the elements in another list) to the tail of the list (makes a new tail).
CObList::FindGets the position of an element specified by pointer value.
CObList::FindIndexGets the position of an element specified by a zero-based index.
CObList::GetAtGets the element at a given position.
CObList::GetCountReturns the number of elements in this list.
CObList::GetHeadReturns the head element of the list (cannot be empty).
CObList::GetHeadPositionReturns the position of the head element of the list.
CObList::GetNextGets the next element for iterating.
CObList::GetPrevGets the previous element for iterating.
CObList::GetSizeReturns the number of elements in this list.
CObList::GetTailReturns the tail element of the list (cannot be empty).
CObList::GetTailPositionReturns the position of the tail element of the list.
CObList::InsertAfterInserts a new element after a given position.
CObList::InsertBeforeInserts a new element before a given position.
CObList::IsEmptyTests for the empty list condition (no elements).
CObList::RemoveAllRemoves all the elements from this list.
CObList::RemoveAtRemoves an element from this list, specified by position.
CObList::RemoveHeadRemoves the element from the head of the list.
CObList::RemoveTailRemoves the element from the tail of the list.
CObList::SetAtSets the element at a given position.

All comparisons are done by value, meaning that the characters in the string are compared instead of the addresses of the strings.

CStringList incorporates the IMPLEMENT_SERIAL macro to support serialization and dumping of its elements. If a list of CString objects is stored to an archive, either with an overloaded insertion operator or with the Serialize member function, each CString element is serialized in turn.

If you need a dump of individual CString elements, you must set the depth of the dump context to 1 or greater.

For more information on using CStringList, see the article Collections.

CObject

CStringList

Header: afxcoll.h

MFC Sample COLLECT
CObject Class
Hierarchy Chart

Show: