Questions tagged [erase]

This tag refers to the process of removing or deleting data, text, files, or memory.

739 questions
9
votes
6 answers

std::map - erase last element

My map is defined as such: map myLocations; where the key is a time string I am only keeping 40 items in this map, and would like to drop off the last item in the map when i reach 40 items. I know that i can't do…
Jason
  • 2,147
  • 6
  • 32
  • 40
8
votes
2 answers

Format SD card in Android

Things should be simple, but as most of the time, in Android, aren't. I need to format the SD card if the user selects the option in my app. Don't ask me why I need to do this if it's already in the OS... not practical but it's a requirement that I…
Alin
  • 14,809
  • 40
  • 129
  • 218
8
votes
2 answers

Removing an element from a std::set while iterating over it in C++17

I've read this SO post, and this one too regarding the erasure of elements from a std::set during iteration. However, it seems that a simpler solution exists in C++17: #include #include int main(int argc,char **argv) { …
OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
8
votes
3 answers

Is remove_if and then erase efficient on vector?

Although there are tens of questions about remove_if + erase for vector. I couldn't find what is the performance of such action. When I write: myVector.erase(remove_if(myVector.begin(), myVector.end(), …
OopsUser
  • 4,642
  • 7
  • 46
  • 71
8
votes
1 answer

c++11: erase using a const_iterator

I believe that since C++11, the erase function of most containers (e.g. std::vector) accepts a const_iterator as parameter: iterator erase (const_iterator position); Still my compilers (GCC 4.8 and Clang 3.2, both using GCC libstdc++) won't allow…
peoro
  • 25,562
  • 20
  • 98
  • 150
8
votes
3 answers

Making an eraser tool for a paint app in iOS

I am creating a paint app and I want to know how to implement the eraser tool. I don't want to have my eraser tool to paint white color because I want to allow users to change the background color. And also, is it possible to set the hardness of the…
user1343911
7
votes
4 answers

C++ Segmentation when using erase on std::list

I'm trying to remove items from a C++ linked list using erase and a list iterator: #include #include #include class Item { public: Item() {} ~Item() {} }; typedef std::list list_item_t; int main(int…
sa125
  • 28,121
  • 38
  • 111
  • 153
7
votes
2 answers

Why map.erase returns iterator?

I've want to erase the elements of the std::map from beginIt to endIt. erase function returns the iterator to the element that follows the last element removed. isn't it endIt ? Why the erase returns iterator ? auto it = m_map.erase(beginIt,…
Gevorg Adamyan
  • 111
  • 1
  • 7
7
votes
2 answers

Does std::vector::erase() invalidate the iterator at the point of erase?

C++03 Standard § 23.2.4.3/3 describes std::vector::erase(iterator position) and says specifically Invalidates all the iterators and references after the point of the erase. Is the iterator at the point of the erase not invalidated? Specifically if…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
7
votes
3 answers

Replacing elements in vector using erase and insert

void replace(vector my_vector_2, string old, string replacement){ vector::iterator it; for (it = my_vector_2.begin(); it != my_vector_2.end(); ++it){ if (*it==old){ my_vector_2.erase(it); …
Nikolai Stiksrud
  • 157
  • 2
  • 4
  • 7
7
votes
3 answers

How to erase path area from canvas (Android)

I need to crop corners on ImageView. Not to round them but erase triangles from each corner. Seems like the only way to do that is to override onDraw method and erase these areas from canvas using Path. The problem is I have not solid color…
Dmitriy
  • 830
  • 3
  • 15
  • 29
6
votes
2 answers

Why "vector.erase()" (in C++) is not behaving as expected?

I have written a simple program to test "vector.erase" feature. There is a simple class (MyClass0) which writes some related message in it's constructor and another in it's destructor. And then there is a vector which contains 4 objects of type…
Meysam
  • 61
  • 3
6
votes
4 answers

C++: Removing all asterisks from a string where the asterisks are NOT multiplication symbols

So basically, I might have some string that looks like: "hey this is a string * this string is awesome 97 * 3 = 27 * this string is cool". However, this string might be huge. I'm trying to remove all the asterisks from the string, unless that…
Casey Patton
  • 4,021
  • 9
  • 41
  • 54
6
votes
2 answers

Removing all elements from one vector that are contained in the other in C++?

I have 2 vectors vc and v2 I want to remove all elements from vc that are contained in v2.I try to do this by 2 nested loops. However the compiler gives an error: Debug Assertion Failed. I would like to ask why is that and how can I fix it? Thanks…
6
votes
4 answers

cppcheck error : Dangerous iterator usage

The code: for(x=abc.begin();x!=abc.end();x++) { if(-----) { ---- abc.erase(x); } } And the error is ::: Dangerous iterator usage After erase the iterator is invalid so dereferencing it or comparing it with another…
eklmp
  • 201
  • 3
  • 9
1 2
3
49 50