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
0
votes
1 answer

Pushing back into a vector of pairs from cin giving wrong results

So i am trying to build a vector and then push back pair items into it. The code goes like this: int main() { int n; cin >> n; vector> o(n,make_pair(0," ")); for(int a0 = 0; a0 < n; a0++) { int x; …
nishant_boro
  • 374
  • 1
  • 2
  • 8
0
votes
1 answer

3D Vector - "No instance of overload function?"

Still relatively new to vectors in C++, the aim of this function is to take 4 arguments, 3 of which define the (x , y , z) position of the data being written, and the 4th being the value that is to be written. as Requested, a picture of the errors…
0
votes
0 answers

Not able to copy the data from one vector to another vector which is inside the structure

The code basically takes in number of nodes(N) and the number of neighbors(k) as the input. Then in the main function's for loop the node will be created which will have all the variables declared in the structure. Then the main function calls the…
0
votes
0 answers

trouble saving object changes in vector

code: #include #include #include #include #include #include "Skirts.h" #include "Tops.h" #include "Bottoms.h" #include "Cart.h" using namespace std; void showMenu() { cout << "WELCOME TO THE…
0
votes
0 answers

C++ list deallocation causes free(): invalid next size (fast): error

I searched other questions about this issue and found a load of them but I do not feel like they fit my peculiar case. I need to retrieve a list of smartcard readers from PCSClite on Debian 9 GNU/Linux, using g++ (Debian 6.3.0-18) 6.3.0. Such list…
bjorn
  • 33
  • 7
0
votes
0 answers

How can push_back change the value of its 'const parameter&'?

I am not an expert in C++, but this is really freaking me out ... I am working on a 3D matrix (>>), and writing overcharged operators to manipule it using push_back. when I add stuff on the first and second 'dimensions', it works fine For…
JPB
  • 11
  • 2
0
votes
1 answer

Push_back odd numbers

So, the goal of the function is to add odd numbers to the array between 1 and a provided integer (inclusive). It seems like a simple task, however, I can't seem to get it to successfully add the integers to the actual array. void…
Granzo
  • 1
  • 3
0
votes
2 answers

cannot use push_back to insert an integer to a 1D/2D vector

I am trying to write a function to extract a slice from a given matrix, where the input is 1D and the slice can be 1D or 2D. I am trying to use the push_back function for this purpose but for some reasons the push_back does not work. I receive an…
Alex
  • 1,194
  • 1
  • 12
  • 20
0
votes
1 answer

Vector push_back seems to be pushing incorrect values

I apologize if this question is naive, but I seem to be having some issues with vector push_back. Following Stroustrup's book, I'm trying to write a code to determine primes [1,100]. Everything I have written thus far seems to work, it correctly…
MVarga
  • 1
0
votes
2 answers

Can anybody help me to do my own Vector class?

I have problem only with the push_back function, the compiler said: CRT detected that the application wrote to memory after end of heap buffer I want to make a push_back function, that adds a new element to the vector's end. #pragma once #include…
Zsembes
  • 11
  • 2
0
votes
0 answers

c++ vector push_back inconsistent behavior

I push back two sets(A={A1,A2,A3},B={B1,B2,B3}) of equal matrices(A1=B1,A2=B2,A3=B3) of same type(CV_32FC) in two different vectors(Va and Vb) of same type. When i compare the contents of the vectors pair by pair(Va[0] vs Vb[0], Va[1] vs Vb[1],Va[2]…
user27665
  • 673
  • 7
  • 27
0
votes
1 answer

vector push_back doesn't work c++

Why is push_back not working as intended? Pretty confused as to why it doesn't work with my current code below using namespace std; void addItem(vector& STRING, string item) { STRING.push_back(item); } int main() { string item; …
Lee Merlas
  • 430
  • 9
  • 24
0
votes
3 answers

C++ curious behavior in vector::push_back()

I have the following data-structure as a class named "Task": private: string name; int computation_time; int period; Furthermore i have a ASCII-File with this content: A 3 10 B 2 12 C 1 11 name = A, computation_time = 3, period = 10 and so…
Askener
  • 291
  • 1
  • 3
  • 4
0
votes
0 answers

Loop-based collision system only works with the last enemy added to vector

I created an Enemy vector and used push_back twice to add two identical enemies. Inside a for loop, I created a collision system to prevent my player from going inside the enemies. However,for some reason it only works with the last enemy added. I…
MrFreeze
  • 23
  • 5
0
votes
2 answers

Why can't I push a vector of integers to a 2-D vector of integers in C++?

Here is my 2D vector of integers. vector> nodes (r*c, vector (5)); using a for loop I am trying to push_back values in this vector. r and c are passed integers to this function. for(i = 0; i < r*c; i++) { …
Ishrat
  • 27
  • 1