Questions tagged [erase]

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

erase
Filter by
Sorted by
Tagged with
50 votes
3 answers
26k views

Erasing vector::end from vector

Does it works correctly (does nothing) when I use vector<T> v; v.erase(v.end()); I want to use something like v.erase(std::find(...)); Should I if is it v.end() or not? There is no info ...
0 votes
0 answers
25 views

STM32 unable to be read

I was halfway through flashing this STM32F411 when it somehow disconnected. And because of that it seems to be unable to be read even through STM32CubeProgrammer. I've searched a lot of stuff trying ...
0 votes
1 answer
81 views

std::list.erase() seems to be rearranging the elements of the list

Consider the following function void removeOdd(list<int>& li) { for(list<int>::iterator it=li.begin(); it!=li.end(); it++) { if((*it)%2) it = li.erase(it); } } ...
-4 votes
1 answer
84 views

c++ while loop equivalent of for loop list traversal + erasure not working

Consider the following function void removeOdd(vector<int>& v) { for(vector<int>::iterator it=v.begin(); it!=v.end(); ) { if((*it)%2) it = v.erase(it); else it++; } } ...
-9 votes
1 answer
390 views

I can not delete the minimum number in the Doubly Linked List and then the next

So, I've been stuck these past three days trying to delete the minimum pointer of the doubly linked list. It always crashes at the point I use min = a.erase(min). I did research saying you "should" ...
2 votes
1 answer
145 views

Is there any possible way to remove the 1st character of a String using O(1) time complexity in C++?

Suppose a String str = "Shajib"; I want to remove the first character 'S' from "Shajib". After removing str = "hajib". I want to perform this task in O(1) Time complexity ...
725 votes
16 answers
1.3m views

How do I erase an element from std::vector<> by index?

I have a std::vector<int>, and I want to delete the nth element. How do I do that? Example: std::vector<int> vec; vec.push_back(6); vec.push_back(-17); vec.push_back(12); vec.erase(???);
0 votes
1 answer
59 views

How to erase an element from a vector using a std::move_iterator?

This is a Josephus Permutation problem, it was solved by using std::move(), but now I have to switch to using std::move_iterator (by using std::make_move_iterator()) However, this doesn't compile: ...
50 votes
9 answers
270k views

HTML how to clear input using javascript?

I have this INPUT, it will clear everytime we click inside of it. The problem: I want to clear only if value = [email protected] <script type="text/javascript"> function clearThis(target)...
1 vote
2 answers
1k views

How to delete an element from a vector of custom objects

I'm trying to delete an item from a 1std::vectorwithstd::vector::erase()` but I keep getting an error. class Person { private: string name; public: void set_name(string name) { this->...
124 votes
7 answers
174k views

How can you erase elements from a vector while iterating?

I want to clear a element from a vector using the erase method. But the problem here is that the element is not guaranteed to occur only once in the vector. It may be present multiple times and I need ...
9 votes
6 answers
11k views

Python securely remove file

How can I securely remove a file using python? The function os.remove(path) only removes the directory entry, but I want to securely remove the file, similar to the apple feature called "Secure Empty ...
0 votes
0 answers
48 views

Delete row/column from matrix/array and retain remaining column and row names in R [duplicate]

I have the following code: # Load BayesFactor package library(BayesFactor) # Call raceDolls data data(raceDolls) # Attribute data to matrix raceDolls2 <- raceDolls Calling raceDolls2 gives the ...
20 votes
15 answers
180k views

Clearing the terminal screen?

I'm reading data from 9 different sensors for my robot and I need to display them all steadily, in the same window so I can compare the values and see if any of the readings is off. The problem I'm ...
0 votes
1 answer
69 views

How to remove previous element in an std::list with a reverse_iterator?

Look at this simple algorithm that remove elements around specific ones : void forwardRemoveAlgorithm(std::list<int> &list, int removeAround) { for(std::list<int>::iterator it=list....
0 votes
1 answer
462 views

Flutter - How can I let a user erase part of an image and make it transparent?

My goal is to let a user selected image (via image_picker) and then use an eraser type tool to modify that image and make it transparent. Any ideas on how I should go about this?
86 votes
8 answers
132k views

Remove elements of a vector inside the loop

I know that there are similar questions to this one, but I didn’t manage to find the way on my code by their aid. I want merely to delete/remove an element of a vector by checking an attribute of this ...
0 votes
1 answer
60 views

Looping through vector std::out_of_range'

I am just practicing c++ on leetcode: https://leetcode.com/problems/asteroid-collision/description/ and I have problem with vector overflow. terminate called after throwing an instance of 'std::...
0 votes
3 answers
203 views

How to use original index of a string to erase single character?

Assume that I have a string 'abcd', and a vector [4,1,3,2] to index the string. For example, first element of vector is 4, so I should remove 4th character in 'abcd' which refers to 'd'. Then the ...
0 votes
3 answers
2k views

How to erase job via gitlab api

I have an issue were I am the owner of a project on a gitlab server, and I can successfully delete all artifacts for a job as listed in the docs.. curl --request DELETE --header "PRIVATE-TOKEN: <...
1 vote
1 answer
121 views

Why is deleting the space? c++ .erase()

I'm solving a kata in codewars, where you have to delete the exclamation mark '!' But, when using .erase(), it deletes the space also. I'm not understanding how it deletes three '!' in a row. This is ...
104 votes
15 answers
222k views

Erase the current printed console line

How can I erase the current printed console line in C? I am working on a Linux system. For example - printf("hello"); printf("bye"); I want to print bye on the same line in place of hello.
4 votes
2 answers
203 views

Calling erase() on an iterator, but not deleting correct element

I am learning C++ and I am working my way double linked lists, but I noticed something very peculiar when I was trying to delete elements from my list. Problem: I am inserting an element before the ...
6 votes
1 answer
98 views

Why do associative containers have an erase overload with non-const iterator argument?

C++11 changed std::vector::erase to take a const_iterator instead of an iterator. The same thing applies to std::deque and std::list, while std::forward_list came in C++11 with erase_after, which also ...
0 votes
1 answer
157 views

STM32F407VE erase sector issues

Never mind ... I shot myself in the foot. I didn't select all the options properly and the program ended up erasing part of itself. \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ I'm doing a bare metal ...
0 votes
2 answers
2k views

Secure delete files on Windows 10 [closed]

I want to securely delete my context of my SSD hard disk. I had a look on sdelete but i realized that file names are not deleted or overwrited. Is there any free tool that i can achieve the above? ...
0 votes
1 answer
112 views

Deleting multiple elements from the map as I am iterating over it

I have a map<string, string> which has UserNames as Keys, and I need to get Ids for those userNames. I am doing this in batches of 20 as calling api for every user may be a bit of an issue. So ...
-4 votes
1 answer
602 views

sedutil-cli is not wiping SATA SSD with PSID [closed]

My goal is to erase all data from the SATA SSD by using sedutil-cli and PSID If during sedutil-cli PSID erase the SSD is reverted back to factory settings then so be it. I made sure to add libata....
1 vote
6 answers
14k views

Remove duplicates in string algorithm

My homework is remove duplicates in a random string. My idea is use 2 loops to solve the problem. 1st one will scan every character in the string. 2nd one will check that character is duplicated or ...
0 votes
0 answers
48 views

C++: Erase specified elements from a STL vector? [duplicate]

Given a std::vector, I want to delete all elements which match a condition. I cannot see any simple way to do this, as I cannot specify a single value for the elements to be deleted. Here is a simple ...
1 vote
1 answer
170 views

C++ boost::range::remove_erase does not work on std::map?

The code snippet std::map<int, int> m = { { 1, 2 }, { 3, 4 } }; boost::range::remove_erase_if( m, [](const auto& it) { return it.first == 1; }); produces the error ...
47 votes
5 answers
149k views

Erase whole array Python

How do I erase a whole array, leaving it with no items? I want to do this so I can store new values in it (a new set of 100 floats) and find the minimum. Right now my program is reading the minimum ...
1 vote
1 answer
240 views

Why is there no std::erase function in C++20. G++ MSYS2 Windows

Apparently std::erase was added in C++20, but my compiler isn't letting me use it for some reason. code #include <iostream> #include <vector> #include <string> #include <string.h&...
4 votes
3 answers
697 views

Why no operator+ for std::list iterators?

I was about to write code like this: std::list<whatevertype> mylist; // ... std::list<whatevertype>::iterator it; for(it = mylist.begin(); it != mylist.end(); ++it) { // ... if(...
-1 votes
1 answer
8k views

C++ - Popping the first element of a vector

I apologize if this is a duplicate. I promise I tried to find an answer first. I want to make a binary heap using a vector. To do so, I have to implement a pop function, that removes the "top." In ...
0 votes
1 answer
262 views

Remove a Chunk of Items from a Vector? [duplicate]

I have a vector full of words and I am trying to erase a chunk of that vector at a specified beginning and end. For example: #include <string> #include <vector> int main() { std::...
0 votes
1 answer
490 views

STM32 Crash on Flash Sector Erase

I'm trying to write 4 uint32's of data into the flash memory of my STM32F767ZI so I've looked at some examples and in the reference manual but still I cannot do it. My goal is to write 4 uint32's into ...
2 votes
5 answers
118 views

Iterators invalidation

Hi I read in C++ primer that adding elements to a vector invalidates the iterators. I don't understand why deleting elements doesn't invalidate them as the following code works std::vector<int> ...
0 votes
0 answers
144 views

Search a pair in unordered_set of pairs from first element in C++

I want to erase the pair: (x,"whatever"), and i want: 1)find an iterator position of the pair with x as first element 2)after that erase the element in the position of the iterator typedef ...
0 votes
1 answer
390 views

dsPIC33 Flash Erase broken

I am having a lot of trouble when it comes to flash erasing on the dsPIC33EP64GP503 and I am hoping someone on here will be able help. I am wanting to store a data struct in the flash program memory ...
0 votes
1 answer
51 views

How to create a "remove_if_not" for a vector<string>

I am trying to make something like this: v.erase(remove_if(v.begin(), v.end(), !pointer_to_func), v.end()); where v is a vector of strings, and pointer_to_func is my function-pointer that looks ...
1 vote
1 answer
149 views

using erase and remove-if: passing more than one argument to function

I would like to iterate and erase items from std::vector, but I wish to compare each item to previous and next items in the vector and to perform some calculations. If a certain condition is met, item ...
0 votes
1 answer
153 views

How to let user erase previous input and output in C++?

I'm in my first weeks of learning programming and I now have a assignment to build a "well functioning" calculator. It has to be able to: -Add -Subtract -Multiply -Divide -Reset -Be able to ...
0 votes
0 answers
111 views

Alternative to erase in vector in c++

I want to use each element only once and don't want to repeat it. Consider below example: v = [1, 2, 2, 3, 4, 5] If I choose 2 at index 1. I don't want the program to use it again. What can I do ...
6 votes
2 answers
270 views

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 ...
3 votes
2 answers
123 views

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 ...
1 vote
1 answer
36 views

Determining landcover %'s (polygon layer) that is not within burned areas (raster layer)

I am trying to extract information on the % of different vegetation cover types within areas that have not been burned. However, the data I was given for the park includes areas that have been burned ...
0 votes
0 answers
47 views

Vector Iterator operation working in test environment - not in main program

So the person here had the same dilemma, and discovered that the vector erase function requires an iterator. I was able to recreate the best answer's example solution in an isolated test environment ...
0 votes
2 answers
111 views

How can i use iterator with vector erase? [duplicate]

I don't know how to use iterator with erase. I wanna use iterator to erase some elements. But my code has some problem. I guess value 'end' and code 'v.erase(it++)' doesn't work. I don't know why. Is ...
-1 votes
2 answers
99 views

Removing section between parenthesis on every line if present

I have a file that I am inputting that has a bunch of lines that look like (* blah blah 4324 blah*) 23. I'm trying to remove everything between the parenthesis and keep the number that's just after ...

1
2 3 4 5
15