📜  如何在 cpp 中删除向量对中的元素 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:49.845000             🧑  作者: Mango

代码示例1
#include 
#include 
#include 

using namespace std;


int main()
{
    vector< pair > v;
    int N = 5;
    const int threshold = 2;
    for(int i = 0; i < N; ++i)
        v.push_back(make_pair(i, i));

    int i = 0;
    while(i < v.size())
        if (v[i].second > threshold)
            v.erase(v.begin() + i);
        else
            i++;

    for(int i = 0; i < v.size(); ++i)
        cout << "(" << v[i].first << ", " << v[i].second << ")\n";

    cout << "Done" << endl;
}