To check if a list is empty in C++ using std::list, you can use the empty() method of the list.
In this example,
myList
.empty()
method of myList
to check if it is empty.empty()
method returns true
if the list is empty, otherwise false
.#include <iostream>
#include <list>
int main() {
std::list<int> myList;
bool isEmpty = myList.empty();
std::cout << "Is list empty: " << (isEmpty ? "true" : "false") << std::endl;
return 0;
}
Is list empty: true
In this tutorial, we learned How to check if a List is Empty in C++ language with well detailed examples.