C++ (Qt)// erasing from vector#include <iostream>#include <vector>using namespace std; int main (){ unsigned int i; vector<unsigned int> myvector; // set some values (from 1 to 10) for (i=1; i<=10; i++) myvector.push_back(i); // erase the 6th element myvector.erase (myvector.begin()+5); // erase the first 3 elements: myvector.erase (myvector.begin(),myvector.begin()+3); cout << "myvector contains:"; for (i=0; i<myvector.size(); i++) cout << " " << myvector[i]; cout << endl; return 0;}
C++ (Qt)// удаляем все отрицательные элементыvoid DeleteNegatives( std::vector<double> & vec ){ size_t i, place = 0, limit = vec.size(); for (i = 0; i < limit; ++i) { if (vec[i] >= 0.0) { if (i != place) vec[place] = vec[i]; ++place; } } vec.resize(place);}
bool is_negative(int val) { return val < 0; }...v.erase(std::remove_if(v.begin(), v.end(), is_negative), v.end());