StunnerAlpha
March 14th, 2010, 02:19 AM
Ey guys, I have a function that takes in two positions and a vector and removes those positions from the vector, like so:
void removeFromTo(vector<string>& vect, long begPos, long endPos){
cout << "beg, end: " << begPos << ", " << endPos << endl;
vect.erase(vect.begin()+begPos, vect.begin()+endPos);
}//removeFromTo
But it fails to remove the first element from the vector, here is some program output:
//elements in the vector:
/ * * / $#
^^^^^^^^^^^^^
0 1 2 3 4 5 6
//beg and end are printed from within the function
beg, end: 0, 4
AFTER REMOVE!!!!!
/ $#
So I still have that first '/'. Here is another example:
e / * * / $#
^^^^^^^^^^^^^^^
0 1 2 3 4 5 6 7
beg, end: 1, 5
AFTER REMOVE!!!!!
e / $#
Yeah, so I don't know what I should do, any help appreciated and thank you.
EDIT:
Another odd thing, I changed the call of the function to:
removeFromTo(actualLine, charTypeAstrkBegCmnt(line, tokensVect[lineNum-1])-1, \
charTypeAstrkEndCmnt(line, tokensVect[lineNum-1])+1);
from:
removeFromTo(actualLine, charTypeAstrkBegCmnt(line, tokensVect[lineNum-1]), \
charTypeAstrkEndCmnt(line, tokensVect[lineNum-1])+1);
and this is my output:
e / * * / $#
beg, end: 0, 5
AFTER REMOVE!!!!!
/ $#
So it seems like it REALLY wants to keep the '/' for some reason.
void removeFromTo(vector<string>& vect, long begPos, long endPos){
cout << "beg, end: " << begPos << ", " << endPos << endl;
vect.erase(vect.begin()+begPos, vect.begin()+endPos);
}//removeFromTo
But it fails to remove the first element from the vector, here is some program output:
//elements in the vector:
/ * * / $#
^^^^^^^^^^^^^
0 1 2 3 4 5 6
//beg and end are printed from within the function
beg, end: 0, 4
AFTER REMOVE!!!!!
/ $#
So I still have that first '/'. Here is another example:
e / * * / $#
^^^^^^^^^^^^^^^
0 1 2 3 4 5 6 7
beg, end: 1, 5
AFTER REMOVE!!!!!
e / $#
Yeah, so I don't know what I should do, any help appreciated and thank you.
EDIT:
Another odd thing, I changed the call of the function to:
removeFromTo(actualLine, charTypeAstrkBegCmnt(line, tokensVect[lineNum-1])-1, \
charTypeAstrkEndCmnt(line, tokensVect[lineNum-1])+1);
from:
removeFromTo(actualLine, charTypeAstrkBegCmnt(line, tokensVect[lineNum-1]), \
charTypeAstrkEndCmnt(line, tokensVect[lineNum-1])+1);
and this is my output:
e / * * / $#
beg, end: 0, 5
AFTER REMOVE!!!!!
/ $#
So it seems like it REALLY wants to keep the '/' for some reason.