Garmaine Staff asked 1 year ago

I would like to know how to display a message when a vector is empty. I know what is required but I don't know how to must be structured.

void displaypoints(const vector<int>& vec) {

    cout << "[";
    for (const auto& i : vec) {
        cout << i << ' ';
    }
    cout << "]" << endl;

};

int main() {

vector <int> myvec {};
vector <int> newvec {1,2,3,4,5};
cout << "myvec";
displaypoints(myvec);
cout << "newvec";
displaypoints(newvec);



if (newvec.at(0) == 1) {
    auto iq = find(newvec.begin(), newvec.end(), 1);
    if (iq != newvec.end()) {
        newvec.erase(iq);
    }



if (newvec.begin(), newvec.end(), 2) {

    auto ik = find(newvec.begin(), newvec.end(), 2);
    if (ik!= newvec.end()) {
    myvec.push_back(*ik);
    newvec.erase(ik);

}  

else if (newvec.begin(), newvec.end(), 3) {

    auto ik = find(newvec.begin(), newvec.end(), 3);
    if (ik!= newvec.end()) {
    myvec.push_back(*ik);
    newvec.erase(ik);


    }
}
}
}

if (newvec.at(0) == 5) {
    auto ik = find(newvec.begin(), newvec.end(), 5);
    if (ik!= newvec.end()) {
    myvec.push_back(*ik);
    newvec.erase(ik);

    }




}

displaypoints(newvec);
displaypoints(myvec);


}

The code above looks for the number 1, erases it then moves 2 to the myvec vector. If there is no 2 then it moves 3 because of the position 0 I have added. There is also another if statement that moves 5 if it is placed at position 0. What I want is another if statement to print a message if there is nothing in the newvec vector.