How to check whether a vector is empty in C++ 17

1 Answer

0 votes
#include <iostream>
#include <vector>
 
int main() 
{
    std::vector<int> v = { 5, 3, 1, 8, 2 };

    v.clear();
    if (std::empty(v))
        std::cout << "Empty\n";
}
 


 
/*
run:
 
Empty
 
*/

 



answered Jun 21, 2020 by avibootz

Related questions

1 answer 385 views
1 answer 265 views
1 answer 296 views
296 views asked Apr 22, 2022 by avibootz
1 answer 224 views
1 answer 298 views
1 answer 376 views
1 answer 294 views
...