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;

Recommended Answers

if(v.empty()) cout<< "v is empty!" <<endl;


Jump to Post

All 4 Replies

if(v.empty()) cout<< "v is empty!" <<endl;


if(v.empty()) cout<< "v is empty!" <<endl;



Well,just using the method


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

@tiredoy empty() always returns a bool. It will always return true if the vector is empty.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.