Partager via


CList::SetAt

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

void SetAt(
   POSITION pos,
   ARG_TYPE newElement 
);

Parameters

  • 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.

Remarks

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.

Example

// 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);      

Requirements

Header: afxtempl.h

See Also

Reference

CList Class

Hierarchy Chart

CList::Find

CList::GetAt

CList::GetNext

CList::GetPrev

Other Resources

CList Members