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
-2
votes
2 answers

speeding vector push_back

I am trying to speed vector::push_back when capacity cant be predicted When reserve is available a vector push_back writes the new element at the end of the container, and then the end marker is moved. After all reserve is used, push_back may…
Saint-Martin
  • 306
  • 3
  • 16
-2
votes
1 answer

C++ how to push_back() members of vector struct

I got this struct: struct human{ int ma; double su; string nev; }; And this part in main() : vector t; fstream inf("in.txt"); I want read in the information from file by using this : while(!inf.eof()) { …
-2
votes
2 answers

Dynamically resizing and filling a vector of vectors in C++

I have a vector that will have an unknown number of rows and 3 columns. The vector should be constructed as follows: a statistical test is made, if it pass a threshold the vector should store infos about it. What I am doing is: vector< vector < int…
-2
votes
1 answer

Funny behavior when pushing onto list in c++

I give up, I simply want to know why push_back is not working as intended. Forget how bad or over complicated my code is. I have a python program which reads a buffer, and displays it line by line from a list. If the last line is not complete,…
-2
votes
1 answer

Push_back function for Class defined vector

I have a vector that takes in class values of a class called Bug which stores a mass and number of legs for each instance. I'm having trouble using the push_back function, and suspect it's just a syntax issue, but can't figure out exactly what I'm…
Cayden
  • 29
  • 5
-2
votes
1 answer

Vector push_back error when compiling

Compiling this segment of code involving using the push_back function for vectors ends up in an error. for (int i=0; i<=n; i++) { if(i==0) { Profit[i].push_back(0); Weight[i].push_back(0); Name[i].push_back(""); …
Megumi Ai
  • 89
  • 2
  • 9
-2
votes
2 answers

How to use push_back with double* pointer

I have the following function in c++ void LocatePulseEdges(int points, double* signal_x, double* signal_y, double* derivative, double threshold, double* left_edge, double* right_edge){ for (int i=0; i
Thanos
  • 594
  • 2
  • 7
  • 28
-2
votes
2 answers

std::vector push_back results in access Violation

Story: I'm making a shared library exposing C code as a wrapper to a C++ static library compiled in VS 2008, so I'm tied to that compiler. In my library I'm trying to do a very simple dictionary to pass data through the shared library boundaries.…
jabozzo
  • 591
  • 1
  • 6
  • 17
-2
votes
1 answer

I cant modify any private fields through public methods from class Artist. I tried adding reference( &) before function names but crashes

addAlbum should add Albums to a certain artist but push_back() doesnt work. as you can see in the picture i cannot modify any private field from Artist class through public methods https://i.stack.imgur.com/Imwf2.png Is this because i didnt write a…
Marian Iconaru
  • 199
  • 4
  • 12
-2
votes
2 answers

How to push an array into a hash in ruby

I didn't find in the internet something that answers specifically my question. I have a hash as follows: hash = {[1111, 4, 20]} And i want to push another array ([3333, 2, 70]) to that hash to get something like: hash = {[1111, 4, 20], [3333, 2,…
Rails Rails
  • 143
  • 1
  • 13
-2
votes
3 answers

Why push_back doesn't push a copy of the source obj?

My code is just like below: class CDemo { public: CDemo() : str(NULL){ }; ~CDemo() { if (str) delete[] str; }; char* str; }; void testVector() { CDemo c; c.str = new char[32]; …
wuchang
  • 3,003
  • 8
  • 42
  • 66
-2
votes
1 answer

C++ postfix incrementation during list push_back

I have a code flush[*it % 4].push_back(*(it++) /= 4); and it was meant to push_back the new value(old value/4) before incrementing the it iterator, is it right like this or how to do it the fastest way to get value from iterator, divide it by 4,…
Lukas Salich
  • 959
  • 2
  • 12
  • 30
-3
votes
1 answer

C++ vector push_back function

So I am pretty new to coding and am having some issues with storing user input into a vector using the push_back function. can some one tell me what I am doing wrong? vector user_nums; switch(selection){ case 'P': case…
-3
votes
1 answer

Storing variables in a vector using push_back

I'm trying to store partial sums in a vector, using push_back and a for loop, however push_back causes an infinite loop for some reason. cin >> n; vector partialSums(n); for (i = 1; i <= partialSums.size(); ++i) { sum = sum + i; …
Michel
  • 3
  • 3
-3
votes
1 answer

vector.push_back doesn't work! [Runtime error]

I've scoured the internet for a solution, but have yet to find one. It seems like push_back doesn't work in this particular code. AddConnection gets called, always and for sure, but whenever I use node.connections.size() it returns 0, which, as…
Jacob
  • 1
  • 4
1 2 3
27
28