Hi,
I'm new to C++, so please bear with me
I'm trying to use the vector STL and I need to delete an element from the vector.
I have created an object called Book and I store them in a vector of Books (vector<Book>).
On certain occasions, I need to delete a Book from the vector.
I'm having trouble with this:
The way I'm trying to do is to transfer the contents of the vector of Books a temp vector. Then I will copy the Books except for the deleted book back to the original vector.
for example:
(There exists a populated vector<Books> books)
Code:
vector<Books> temp;
string title; //title of book to be deleted
books.swap(temp);
for (int i=temp.size()-1; i>=0; i--)
{ if (temp[i].getTitle() != title)
{ books.pushback(temp.pop_back()); //ERROR
}
else
{temp.popback();
}
}
However, i get an error like this:
invalid use of void expression.
is there anyway I can do this operation?
Thanks a lot!!