The usage of CSTRINGLIST in C++

  • 2020-04-02 03:05:41
  • OfStack

CStringList class members

structure

CStringList

Construct an empty CString The object list

First/last access

GetHead

Returns the header element in this list (which cannot be empty)

GetTail

Returns the trailing element in this list (which cannot be empty)

operation

RemoveHead

Remove the element from the head of the list

RemoveTail

Remove the element from the end of the list

AddHead

Adding an element to the head of a list (or all of the elements in another list) generates a new head

AddTail

Adding an element to the end of a list (or all of the elements in another list) generates a new tail

RemoveAll

Delete all elements in this list

repeat

GetHeadPosition

Returns the position of the header element in the list

GetTailPosition

Returns the position of the tail element in the list

GetNext

Gets the next element to repeat

GetPrev

Gets the previous element for repetition

Acquisition/modification

GetAt

Gets the element at the given location

SetAt

Sets the element at the given location

RemoveAt

Removes an element specified by location from this list

insert

InsertBefore

Inserts a new element before a given location

InsertAfter

Inserts a new element after a given location

search

Find

Gets the position of the element specified by the string value

FindIndex

Gets the location of the element specified by a zero-based index

state

GetCount

Returns the number of elements in this list

IsEmpty

Test if the list is empty (no elements)

CStringList is a CString linked list, an alternative to STL in MFC programming, and is more concise to use.

Insert data: AddTail (); AddHead ()

Remove data: RemoveAll(); RemoveAt (); RemoveHead (); RemoveTail ()

Get the number of elements: GetCount()

GetAt(cstringlist.findindex (index))//index is an integer

GetHead(); GetTail (),

The best way to do this is not to use the POSITION variable, but to use FindIndex.

Initialization:


CStringList listFileName;
listFileName.RemoveAll();

Add operation:


listFileName.AddTail(szFullPathName);

Traversal operation:


POSITION rPos;
rPos = listFileName.GetHeadPosition();
while (rPos != NULL)
{
strFileName = listFileName.GetNext(rPos);
strLog += "/r/n" + strFileName;
}

The above is all the content of this article, I hope you can enjoy it.


Related articles: