-
Deleting vector parts?
(WinXp, Borland C++ Free command line)
Ok, its come time I need to delete a nullified part of my vector.
Heres my code summed up:
Code:
int main() {
vector <int> X;
x.push_back(1);
x.push_back(2);
x[1]=0;
x.erase(x[1])
}
But my compiler doesnt like this at all.
Code:
Warning W8012 C:\PlatformClass.h 141: Comparing signed and unsigned values in function Platform::Fall()
Error E2285 C:\MOPEngine.h 168: Could not find a match for 'vector<Platform,allocator<Platform> >::erase(Platform)' in function PlatBreaker()
*** 1 errors in Compile ***
C:\Borland\BCC55\Bin>
I did a google search for this, and something about iterators or something poped up, but how do I return an iterator thats not the absolute beggining or absolute end of a vector? In this example it could work, but in my real code rend and rbegin wont work.
So, how do I make this happy by giving it an iterator (that is what it wants right?)
-
-
Code:
#include <iostream>
#include <vector>
void ShowContentsViaIterator(std::vector<int>& v)
{
std::vector<int>::iterator iter;
for (iter=v.begin();iter!=v.end();++iter)
{
std::cout<<*iter<<std::endl;
}
}
int main() {
std::vector <int> x;
x.push_back(1);
x.push_back(2);
x[1]=0;
std::cout<<"Before erase:"<<std::endl;
ShowContentsViaIterator(x);
x.erase(x.begin()+1);
std::cout<<"\nAfter erase:"<<std::endl;
ShowContentsViaIterator(x);
}
-
Lol, 7stud, that was probably the mosty helpful 1-word statement ever :P. Thank you guys very much!