Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CList::SetAt

CList::SetAt

A variable of type POSITION is a key for the list.

void SetAt( 
   POSITION pos, 
   ARG_TYPE newElement  
);

pos

The POSITION of the element to be set.

ARG_TYPE

Template parameter specifying the type of the list element (can be a reference).

newElement

The element to be added to the list.

It is not the same as an index, and you cannot operate on a POSITION value yourself. SetAt writes the element to the specified position in the list.

You must ensure that your POSITION value represents a valid position in the list. If it is invalid, then the Debug version of the Microsoft Foundation Class Library asserts.

// Define myList.
CList<CString,CString&> myList;

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

// Replace CString("ABC") with CString("CBA")
POSITION pos = myList.Find(CString(_T("ABC")));
myList.SetAt(pos, CString(_T("CBA")));

// Verify CString("ABC") is not in the list.
ASSERT(myList.Find(CString(_T("ABC"))) == NULL);      

Header: afxtempl.h

Show:
© 2015 Microsoft