C++ 如何擦除前7列加上最后一列,即第9列,只在3d矢量中保留第8列<;向量<;配对<;int,int>&燃气轮机>;?

C++ 如何擦除前7列加上最后一列,即第9列,只在3d矢量中保留第8列<;向量<;配对<;int,int>&燃气轮机>;?,c++,C++,如何擦除前7列加上最后一列(第9列),只在3d向量(如向量)中保留第8列 这很好: for (vector<vector<pair<int,int> > >::iterator it = allPathCoordinates.begin(); it != allPathCoordinates.end(); it += 1) { v_temp = *it; for(vector<pair<int,int> >:

如何擦除前7列加上最后一列(第9列),只在3d向量(如
向量
)中保留第8列

这很好:

for (vector<vector<pair<int,int> > >::iterator it = allPathCoordinates.begin();
     it != allPathCoordinates.end();
     it += 1)
{
  v_temp = *it;
  for(vector<pair<int,int> >::iterator it2 = v_temp.begin();
      it2 != v_temp.end();
      ++it2)
  {
    apair = *it2;
    openPoints[apair.first][apair.second] = 0;
    closedPoints[apair.first][apair.second] = 1;
    allObstacles[apair.first][apair.second] = Wall;
    point[apair.first][apair.second] = Purple;
  }
}
cout << "allPathCoordinates.size():"
     << allPathCoordinates.size() << endl; // 79512
cout << "sizeof(allPathCoordinates):"
     << sizeof(allPathCoordinates) << endl; //24

vector< vector<pair<int,int> > >::size_type sz;
sz = allPathCoordinates.capacity();
cout <<  "capacity: "  <<  sz  <<  '\n';

allPathCoordinates.erase(allPathCoordinates.begin(),
                         allPathCoordinates.begin()+7);
cout << "allPathCoordinates.size():"
     << allPathCoordinates.size() << endl;
cout << "sizeof(allPathCoordinates):"
     << sizeof(allPathCoordinates) << endl;

sz=allPathCoordinates.capacity();
cout<< "capacity: " << sz << '\n';
for(vector::iterator it=allPathCoordinates.begin();
it!=allPathCoordinates.end();
it+=1)
{
v_temp=*它;
对于(vector::iterator it2=v_temp.begin();
it2!=v_temp.end();
++it2)
{
apair=*it2;
openPoints[apair.first][apair.second]=0;
关闭点[apair.first][apair.second]=1;
障碍物[第一][第二]=墙;
点[apair.first][apair.second]=紫色;
}
}

cout如果我理解你的问题,你需要的是在
擦除后调用

我们也可能不同意
向量的“列”是什么。让我用一个简单的程序来解释:

#include <iostream>
#include <vector>
#include <iomanip>
#include <utility>

using std::cout;
using std::vector;
using std::pair;

using thing = vector<vector<pair<int,int>>>;

void print ( thing &a ) {
    for ( auto && row : a ) {
        for ( auto && col : row ) {
            cout << std::setw(6) << col.first << ','
                 << std::setw(3) << col.second;
        }
        cout << '\n';
    }
    cout << "\nouter vector size: " << a.size()
         << " capacity: " << a.capacity() << '\n';
    cout << "inner vector size: " << a[0].size()
         << " capacity: " << a[0].capacity() << "\n\n";
}

int main() {
    thing a = {
        {  {1,  2},  {3,  4},  {5,  6} },   // <- that's row 0: a[0]
        {  {7,  9}, {10, 11}, {12, 13} },
        { {14, 15}, {16, 17}, {18, 19} },
        { {20, 21}, {22, 23}, {24, 25} }
    };  // ^^^^^^ 
        // This is a column, all the pairs a[i][0] for 0 <= i < N

    print(a);

    // erase the second row
    a.erase(a.begin() + 1);
    a.shrink_to_fit();

    print(a);

    // erase the second column
    for ( auto && row : a ) {
        row.erase(row.begin() + 1);
        row.shrink_to_fit();
    }

    print(a);

    return 0;
}

我不太明白。你的意思是你想从
allPathCoordinates
中删除除元素8之外的所有元素吗?你不能只复制该列吗?谢谢你指出了正确的方向,但我需要帮助理解为什么要将allPathCoordinates而不是你的“东西”给出以下输出:{44228}{441288}{440 288}{442263}{441263}{441263}{440,263}{442,238}{441,238}{440,238}谢谢你给我指出了正确的方向。我的评论有很多字符要匹配,所以你能告诉我如何找到你并给出完整的评论吗。你可以在bo找到我。nystedt@sfr.fr.@不客气。编辑您的问题并添加初始数据将是一个好主意(至少是最重要的)以及您获得和期望的产出。
#include <iostream>
#include <vector>
#include <iomanip>
#include <utility>

using std::cout;
using std::vector;
using std::pair;

using thing = vector<vector<pair<int,int>>>;

void print ( thing &a ) {
    for ( auto && row : a ) {
        for ( auto && col : row ) {
            cout << std::setw(6) << col.first << ','
                 << std::setw(3) << col.second;
        }
        cout << '\n';
    }
    cout << "\nouter vector size: " << a.size()
         << " capacity: " << a.capacity() << '\n';
    cout << "inner vector size: " << a[0].size()
         << " capacity: " << a[0].capacity() << "\n\n";
}

int main() {
    thing a = {
        {  {1,  2},  {3,  4},  {5,  6} },   // <- that's row 0: a[0]
        {  {7,  9}, {10, 11}, {12, 13} },
        { {14, 15}, {16, 17}, {18, 19} },
        { {20, 21}, {22, 23}, {24, 25} }
    };  // ^^^^^^ 
        // This is a column, all the pairs a[i][0] for 0 <= i < N

    print(a);

    // erase the second row
    a.erase(a.begin() + 1);
    a.shrink_to_fit();

    print(a);

    // erase the second column
    for ( auto && row : a ) {
        row.erase(row.begin() + 1);
        row.shrink_to_fit();
    }

    print(a);

    return 0;
}
     1,  2     3,  4     5,  6
     7,  9    10, 11    12, 13
    14, 15    16, 17    18, 19
    20, 21    22, 23    24, 25

outer vector size: 4 capacity: 4
inner vector size: 3 capacity: 3

     1,  2     3,  4     5,  6
    14, 15    16, 17    18, 19
    20, 21    22, 23    24, 25

outer vector size: 3 capacity: 3
inner vector size: 3 capacity: 3

     1,  2     5,  6
    14, 15    18, 19
    20, 21    24, 25

outer vector size: 3 capacity: 3
inner vector size: 2 capacity: 2