This tag refers to the process of removing or deleting data, text, files, or memory.
Questions tagged [erase]
739 questions
4
votes
2 answers
Is erasing the end iterator an oversight in the standard or a design decision?
The standard library containers allow us to erase ranges denoted by iterators first and last.
std::vector bar;
// first it last it
bar.erase(bar.begin(), bar.end());
The standard says that the first iterator must be valid and…

Fibbs
- 1,350
- 1
- 13
- 23
4
votes
4 answers
Erase elements in vector using for loop
How do I use a for loop to erase elements from a vector by its index ? I am getting a vector out of range error. I have a sample code below.
vector to_erase = {0, 1, 2};
vector data = {3, 3, 3, 3};
for(int i = 0; i <…

RuiQi
- 488
- 2
- 14
4
votes
4 answers
Vector.erase(Iterator) causes bad memory access
I am trying to do a Z-Index reordering of videoObjects stored in a vector. The plan is to identify the videoObject which is going to be put on the first position of the vector, erase it and then insert it at the first position. Unfortunately the…

xon1c
- 423
- 5
- 12
4
votes
2 answers
vector::erase with pointer member
I am manipulating vectors of objects defined as follow:
class Hyp{
public:
int x;
int y;
double wFactor;
double hFactor;
char shapeNum;
double* visibleShape;
int xmin, xmax, ymin, ymax;
Hyp(int xx, int yy, double ww, double hh, char s): x(xx),…

matt
- 87
- 5
4
votes
5 answers
C++ - Deleting a vector element that is referenced by a pointer
Well, I don't know if it is possible, but the thing would be:
struct stPiece
{
/* some stuff */
stPiece *mother; // pointer to the piece that created this one
};
vector pieces;
Is it possible to erase the piece referenced by 'mother'…

huff
- 1,954
- 2
- 28
- 49
4
votes
2 answers
STL Allows Erasing a map's key/value using an iterator pointing to a different map?
So, what I stumbled upon is that:
std::map map1;
std::map map2;
map1[2.5] = 11;
map1[3.5] = 12;
map2[2.5] = 21;
map2[3.5] = 22;
std::map::iterator iterMap1 = map1.find(2.5);
//I will now try to erase a…

Harshit Sureka
- 43
- 4
4
votes
1 answer
Does std::list's end() iterator position change when erasing?
In the following loop I'm using a pre-calculated end iterator:
std::list::iterator end = MyList.end();
for (std::list::iterator it = MyList.begin(); it != end ;)
it = MyList.erase(it);
When erasing an element in a std::list, can the…

Subway
- 5,286
- 11
- 48
- 59
4
votes
4 answers
Eraser with PorterDuff.Mode.CLEAR always draws a black line, where i want to delete
Can i make it draw the path, where I move my finger to delete with a transparent line, or not draw at all?
This is how i instantiate my eraser:
OnClickListener eraseListener = new OnClickListener() {
@Override
public void…

rosu alin
- 5,674
- 11
- 69
- 150
4
votes
4 answers
what does C++ string erase return *this mean?
So the C++ string function
string& erase ( size_t pos = 0, size_t n = npos )
returns *this. What does that mean? Why do I need it to return anything?
Example
string name = "jimmy";
name.erase(0,1);
will erase j and become immy, but why do I…

bluejimmy
- 390
- 6
- 14
4
votes
1 answer
What does the following syntax with the combination of erase and remove mean?
Possible Duplicate:
Difference between erase and remove
suppose i have a container.... what does the following mean.
c.erase(remove(c.begin(),c.end(),99),c.end());
aren't erase and remove the same? What is the specific function of erase and…

Saikiran
- 143
- 2
- 7
4
votes
3 answers
Erase by iterator on a C++ STL map
I'm curious about the rationale behind the following code. For a given map, I can delete a range up to, but not including, end() (obviously,) using the following code:
map myMap;
myMap["one"] = 1;
myMap["two"] = 2;
myMap["three"] =…

Component 10
- 10,247
- 7
- 47
- 64
4
votes
3 answers
How to implement touch smooth image eraser in android?
I have already seen fingurePaint.java from API demos. I want to implement touch smooth eraser to erase parts of the image by touch move in android.
fingurePaint told me to implement this
mPaint.setXfermode(new…

Sanchit Paurush
- 6,114
- 17
- 68
- 107
3
votes
3 answers
Erasing element from Vector
In C++, how can I delete an element from a vector?
Delete it right from where it is, i.e. let the vector resize
Swap the element to be deleted with the last element s.t. pop_back() can be used (which I hope doesn't involve copying everything…

Ben
- 15,938
- 19
- 92
- 138
3
votes
2 answers
How to iterate through a set when members might be removed during iteration?
This simple program is a minimal version of a problem I was having. I have an unordered set of pointers to objects, and while iterating through that set, some of the objects were supposed to be erased from the set. In my larger program, this was…

Apra24
- 31
- 1
3
votes
5 answers
How to erase a string if it contains any character in a set [c++]
I am new to C++ and could not find a solution in any post for this.
I have a vector of strings and I wish to erase a string from this vector if it contains any of these symbols: {'.', '%', '&','(',')', '!', '-', '{', '}'}.
I am aware of find(),…

Mi_cal2002
- 35
- 5