Clearing and Erasing elements in Vector of Vectors

I don't have much of experience in programming and in C++ , so maybe the question is a bit silly for the pros.
But anyways the problem i am having is that i need to clear a vector of vector if it is positive and if negative then clear only that particular element(so i am using erase statement) in the vector.But i am having some syntax errors and not able to fix it. It will be great if someone could help me out of this.Thanks in advance.

void DavisPutnam(vector< vector<int> > cnf)
{
for (unsigned int i=0 ;i< cnf.size();i++)
{
for (unsigned int j=0 ;j< cnf[i].size();j++)
{
if (cnf[i].size()== 1 && cnf[i][j]>0)
{
cnf[i].clear();

} else
{
cnf[i][j].erase();
}
}
Do not overcomplicate. You seem to desire to remove each integer element, where the element's value is larger than 0.

The operation will not change the size of cnf.

There is a "erase-remove idiom" that can be used here. https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom

1
2
3
for ( auto v : cnf ) { // range for syntax
  v.erase( std::remove_if( v.begin(), v.end(), is_positive ), v.end() );
}

(You do need the bool is_positive(int) too.)
Topic archived. No new replies allowed.