0

What is the easiest way to check if a vector is empty?

#include <iostream>
#include <vector>

using namespace std;

typedef std::vector<double> Vec;
typedef std::vector<Vec> Mat;

int main(){
    Vec v; // this is what i consider to be an "empty" v
    if( /*check if v is empty here*/ ) cout<< "v is empty!" <<endl;
return 0;
}
4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by NathanOliver
0
if(v.empty()) cout<< "v is empty!" <<endl;

:icon_rolleyes:

Gracias!

0

Well,just using the method

v.empty()

If the vector is empty,it will return a bool value .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.