Linked Questions

38 votes
5 answers
76k views

How do I remove the ith item from a std::vector? I know I want to delete the ith element. I have int i; and std::vector<process> pList; where process is a struct. I want to do something ...
kralco626's user avatar
  • 8,696
9 votes
4 answers
8k views

I have a vector a storing values [0 1 2 3 5] and other vector removelist storing the indexes to be removed [0 1 2] in order to leave [3 5] at the end. When I'm implementing the following code, it ...
Tleung's user avatar
  • 169
4 votes
1 answer
4k views

I have a vector of pairs std::vector<int,double> lambda; I would like to remove the kth element, i.e lambda.erase(&lambda[k]); lambda.erase(lambda[k]); Both of these attempts throws a no ...
user avatar
-1 votes
2 answers
846 views

Here is the 2d vector [[1,3],[2,6],[8,10],[15,18]] I want to delete the 2nd row which is [2,6] I tried following to erase the 1st row matrix[1].erase(intervals[1].begin(),intervals[1].end()); after ...
saurin's user avatar
  • 3
3 votes
1 answer
266 views

I have an object that contains an STL vector. I start with the vector being size zero and use push_back to add to it. So, push_back works fine. In my code, each element in the vector represents an ...
Charlie Crown's user avatar
0 votes
1 answer
372 views

#include <iostream> #include <vector> #include <cstdlib> #include <time.h> using namespace std; void makeVector(); void breakVector(); vector<char> asciiChar; vector&...
wacey's user avatar
  • 23
-8 votes
1 answer
448 views

/* So the teacher built the main and a prototype for a class that builds and modifies a phone book. Right now I'm barely defining the class functions, but ran into trouble defining one of his ...
BrockObama's user avatar
0 votes
1 answer
552 views

How I can access and print the value of unique_ptr, how to delete the 3rd value and accordingly reduce the container's value without making segmentation fault. #include <memory> #include <...
Rose's user avatar
  • 21
0 votes
0 answers
383 views

I'm quite stuck on this function for a c++ program. Instructions Write a function called RemoveGrades that takes the student array and grade vector as parameters, it asks the user for a valid ...
Frosty's user avatar
  • 1
0 votes
0 answers
71 views

I've got a problem : I have a vector vector<TSquare> SquaresList; and when I try to delete an member of it (which is a TSquare instance)delete SquaresList[l]; it says this: main.cpp|499|error: ...
RandomMatt's user avatar
127 votes
12 answers
104k views

I have a vector of IInventory*, and I am looping through the list using C++11 range for, to do stuff with each one. After doing some stuff with one, I may want to remove it from the list and delete ...
EddieV223's user avatar
  • 5,373
221 votes
6 answers
29k views

There are several references for the C++ standard library, including the invaluable ISO standard, MSDN, IBM, cppreference, and cplusplus. Personally, when writing C++ I need a reference that has quick ...
Kerrek SB's user avatar
  • 480k
23 votes
8 answers
14k views

I found myself writing the following a lot: int location =2; vector<int> vec; vector<int>::iterator it=vec.begin(); /..../ std::advance(it, location); instead of it= it + 5; what is ...
vehomzzz's user avatar
  • 45.1k
21 votes
6 answers
12k views

I've a std::vector<int> and I need to remove all elements at given indexes (the vector usually has high dimensionality). I would like to know, which is the most efficient way to do such an ...
Peter's user avatar
  • 281
5 votes
3 answers
31k views

I have the following code in C++: #include <iostream> #include <cstdlib> #include <ctime> #include <vector> int main () { srand(time(0)); int noOfElements = 9; for ...
LazySloth13's user avatar
  • 2,505

15 30 50 per page