Questions tagged [erase]

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

739 questions
3
votes
3 answers

Erase in a loop with a condition in C++

Is there a better way to write: for (auto i = container.begin(); i != container.end();) { if (condition(i)) { i = container.erase(i); continue; } ++i; } This code does what I want, but it feels like bad style. How can…
Fractale
  • 1,503
  • 3
  • 19
  • 34
3
votes
3 answers

C++ map::erase() does not erase data

I'm trying to test C++ map::erase() with the following code: //file user.h #include #include #include using namespace std; class User { string name; int id; public: User(const string& name, int id) :…
Marco
  • 391
  • 4
  • 18
3
votes
1 answer

Erase Part of Bitmap with another Bitmap

Let me preface this with a real life product; You may remember in Elementary school, they had scratch paper which basically consisted of a rainbow-colored sheet of paper with a black film on top. You would take a sharp object and peel away the black…
3
votes
1 answer

Generic erase function

I need to erase elements of different stl and boost containers by an iterator. Sometimes I also need to do that with a reverse_iterator so I wanted to wrap that into a generic function (set). According to this: Iterator invalidation rules it should…
Flamefire
  • 5,313
  • 3
  • 35
  • 70
3
votes
1 answer

std::vector::erase deleting last element instead of first

I am fairly new to c++, but had a question about vectors. My goal is to remove an element from the vector using erase once I hit my out of bounds condition. This all seems to work fine, except that when I call erase, it will be pointing to the…
ColdFire
  • 31
  • 2
3
votes
3 answers

vector::erase does not erase the desired element, but instead erases the last element from the vector

I've been working on learning c++, but now I'm stuck with a problem that really confuses me. The problem is that when i try to erase an element from a vector, the erase function does not erase the element that i wanted to be erased, but instead…
Tuotau
  • 41
  • 3
3
votes
0 answers

c++ map erase SIGSEGV segmentation fault

I'm debugging my program now and I get segmentation fault when erasing an element from a map. I added malloc hook to my programs which looks as follow: (UPDATED) #pragma once #include #include #include static void…
MoonBun
  • 4,322
  • 3
  • 37
  • 69
3
votes
2 answers

How do I remove everything in a string prior to a specific word in C++?

SEE FINAL UPDATE FOR SOLUTION This is for school, so I request hints, not blatant answers if possible. I need to take the phrase "My Name current community college" and output "Current Community College" I already have a loop to capitalize current…
cma0014
  • 1,517
  • 3
  • 11
  • 9
3
votes
2 answers

Erase or delete a line drawn on a TImage Canvas

this is my first question in stackoverflow , i've searched everywhere a cross the web before posting here,so you guys are my last chance i'm making a little program in Delphi xe5 which consist in drawing lines on a football pitch(TImage) using…
MKaiser
  • 45
  • 1
  • 6
3
votes
1 answer

How to erase a multidimensional variant array holding objects and numbers

I have the following array which I want to erase, or at least clear: Dim arrFiles() As Variant The array has two columns, lngIndex and objFile. I remember reading somewhere that erase only works in certain conditions. Will erase work on this type?…
3
votes
5 answers

C++ Clearing vector of pointers to dynamically-allocated object causes exception?

I have a class called ClassA. This ClassA holds a vector of pointers to dynamically allocated objects of class ClassB. The destructor for ClassA looks like this: ClassA::~ClassA() { for (vector::iterator i = m_vActiveB.begin(), e =…
Raiden616
  • 1,545
  • 3
  • 18
  • 42
3
votes
1 answer

how to erase smoothly in android?

i want the eraser to erase smoothly but in my activity by default it erase the lines on touch draw and erase the lines on touch is not proper.my code what i had worked on. public void Draw(){ count=1; bmp =…
GOPATHI
  • 91
  • 1
  • 6
3
votes
2 answers

C++ : deleting multiple elements of a list while iterating the list

I know how do erase elements of a list, and that erase return a valid iterater. My problem is, that I want to remove not just one element but multiple. Actuall my code is like for(list::iterator it=currentLevel->begin();…
Name
  • 33
  • 1
  • 3
3
votes
3 answers

Destruction of an object when erasing it from std::map

I was curios if default destructor is called, when I'm removing an element from an std::map. Here is an example which I have made: class CTestMap{ public: CTestMap() { std::cout << "default constructor called" << std::endl; } …
JosiP
  • 2,619
  • 5
  • 29
  • 33
3
votes
2 answers

Replacing items in a list using a C++ std::list iterator

The basic structure of my code is: using namespace std; void recursiveFunction(list &jobs,...){ list::iterator i; int ii; //code missing for(i=jobs.begin(); i != jobs.end(); ++i){ //more code missing …
DylanTheWebb
  • 33
  • 1
  • 1
  • 3