C++ vector empty() function
Example
Find out if a vector is empty or not:
vector<string> cars;
cout << cars.empty() << "\n";
cars = {"Volvo", "BMW", "Ford", "Mazda"};
cout << cars.empty();
Try it Yourself »
Definition and Usage
The empty()
function checks whether a vector is empty or not.
It returns 1
if the vector is empty and 0
otherwise.
Syntax
vector.empty();
Parameter Values
None.
Technical Details
Returns: | A boolean value:
|
---|
Related Pages
Read more about vectors in our Vector Tutorial.
Read more about booleans in our Booleans Tutorial.