Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > vector<vector<int>> - вложенные вектора


Автор: Iganga 3.12.2008, 23:59
Доброго времени суток уважаемые форумчане.

У меня проблема. Как можно удалить строку из вектора вложенного?

Код

using namespace std;
typedef vector<vector<int>> MySuperVectorParent;
typedef vector<int> MySuperVectorChild;
const int ARRAY_SIZE = 10;

void ShowToSuperVector(MySuperVectorParent &theVector);
//void DeleteRowFromMatrix(MySuperVectorParent &theVector);
void main()
{
    
  MySuperVectorParent theVector(ARRAY_SIZE,MySuperVectorChild(ARRAY_SIZE));
 for(int i=0;i<ARRAY_SIZE;i++)
  {
     for(int j=0;j<ARRAY_SIZE;j++)
     {
         theVector[i][j] = rand();
     }
 }
 cout<<"Row to delete: \n";
 int row_to_delete=0;
 cin>>row_to_delete; 
 theVector[row_to_delete].erase(std::remove(theVector[row_to_delete].begin(),theVector[row_to_delete].end(),0));
  //theVector.erase(theVector.begin()+1,theVector.begin()+1);
  ShowToSuperVector(theVector);
}

void ShowToSuperVector(MySuperVectorParent &theVector)
{
  if(theVector.empty())
  {
      cout<<"Matrix is empty.\n";
      return;
  }
  for(int i=0;i<theVector.size();i++)
  {
     cout<<"col "<<i<<"   ";
  }
  cout<<"\n\n\n";
  for(int i=0;i<theVector.size();i++)
  {
     for(int j=0;j<theVector.size();j++)
     {
         cout<<theVector[i][j]<<"   ";
         if(theVector[i][j]<40000 && theVector[i][j]<1000)
     
         cout<<"  ";
     }   
     cout<<"\n";
  }
}



Заранее благодарен.

Автор: J0ker 4.12.2008, 00:42
Код

theVector.erase(theVector.begin() + row_to_delete);

Автор: Iganga 4.12.2008, 08:40
Я благодарен очень)))
Ночью сидел вкурить не мог в чем дело. Все оказывается очень просто.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)