Questions tagged [push-back]

is the action of adding an element at the end of a container.

push-back is the action of adding an element at the end of a container.

420 questions
1
vote
6 answers

How to keep an iterator dereferenceable when its vector is added to?

Let's say I have this code: std::vector objects; std::vector::iterator iter; for (iter = objects.begin(); iter != objects.end(); iter++) { if (condition) objects.push_back(new Object()); } However, when push_back…
Sk8torchic
  • 11
  • 1
1
vote
3 answers

C++ crashing:push_back on nested vectors

#include #include using namespace std; struct Neighbor { int index; int weight; Neighbor(int, int); }; Neighbor::Neighbor(int index, int weight) { Neighbor::index = index; Neighbor::weight = weight; } void…
1
vote
1 answer

Android Fatal signal 7 (SIGBUS), code 1, fault addr 0xb8509ce1 in tid 32190 (com.example)

In my app, I use of C++ code to complie.There is a function in xxx.cpp like this: void Cache::addRequest(SREQUEST req) { m_reqs.push_back(req); } When my app call this function, it's throw the run-time error: Fatal signal 7 (SIGBUS), code 1,…
user1010439
  • 43
  • 2
  • 6
1
vote
2 answers

c++ Push_back type with multiple

I have the following C++ Code... struct myType { int SID; int IID; std::string myString; }; std::vector _type; The problem is when i do this... for (int x = 1; x < 82432; x++) { _type.push_back(myType()); } it give me…
1
vote
2 answers

vector destroys objects but does not construct their replacements?

#include #include using namespace std; class cMember { public: int id; cMember(); ~cMember(); }; cMember::cMember() { cout<<"member constructor\n"; } cMember::~cMember() { cout<<"member…
BDO
  • 13
  • 4
1
vote
6 answers

c++ garbage values in vector of pointer

When I do: for(i=0; i
user3794176
  • 75
  • 1
  • 9
1
vote
1 answer

deque empty after push_back a deque

I tried to read lines from file, push every 5 lines into one deque dq, then push dq into a deque ques. The dq successively got 5 lines, but after push_back the dq into ques, the debuger shows that one empty queue was inserted into ques, shown below…
X. L
  • 601
  • 1
  • 7
  • 11
1
vote
2 answers

push_back private vectors with 2 methods, one isn't working

I have a class with a private vector of doubles. To access or modify these values, at first I used methods such as void classA::pushVector(double i) { this->vector.push_back(i); } double classA::getVector(int i) { return vector[i]; } This worked…
jmclem
  • 99
  • 1
  • 1
  • 5
1
vote
1 answer

Using the same vector without the resize() part

I have a question about std::vector - vector vec(1,0); while(//something_1) { while(//something_2) { ... vec.pushback(var) ... } process(vec.size()); //every iteration- different size vec.clear(); …
user1673206
  • 1,671
  • 1
  • 23
  • 43
1
vote
3 answers

C++ possible constructor error violation writing location

I have added these functions to my code, and my program started crashing randomly showing Unhandled exception at 0x6C7B52E7 (SDL2.dll) in SDL_2.exe: 0xC0000005: Access violation writing location 0xFF00000C. Debugger shows at completely random…
1
vote
2 answers

c++ Crossover genetic algorithm push_back vector overwrites the old one

I have problem with my code. I'm trying to do a crossover of 4 parents. The problem is the push_back vector keeps overwriting the upper one if there is the same value in the vector. For example, parent 1 = 101 parent 2 = 200 parent 3 = 101 parent 4…
1
vote
3 answers

ASP form losing file attachments on postback

I have an aspx form that contains a series of user inputs and then a submit button that packages that info and sends an email with the parsed data and any attachments. I'm using an asp:fileupload for the user to attach files to the email, and on the…
1
vote
2 answers

push_back implementation internal

In std::vectors push_back implemetation, when size()==capacity() , the part, that it allocates two times more place and copy the elements of old , I want to ask, the most effective way of that copying?
Seno Alvrtsyan
  • 241
  • 1
  • 11
1
vote
0 answers

Add value to row of multidimensional vector c++ with push_back

I want to push_back only one column in a multidimensional vector. How do I only access and push_back the vector at a specific row with an int? typedef vector Row; typedef vector Matrix; int N = 3; Matrix restricted(N+1, Row(0)); And then…
user3377716
1
vote
1 answer

C++ vector.push_back adds objects twice when adding an object once

I am creating a DirectX program which needs to be able to dynamically add objects into a list (or vector) for use the render function. I need to be able to access these objects through the "[]" operator which is the reason i am using vectors instead…
Conner Tenn
  • 63
  • 3
  • 8