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

How to "push_back" in Processing

I am trying to create Space Invaders with Processing, and I am currently working on making the shooting mechanic. I have set up where when you press T, I will make a new variable called newBullet based off the class Bullets. I will say that it is…
ThatGuy
  • 107
  • 1
  • 2
  • 11
1
vote
2 answers

Overloading push_back() in vector to allow non-duplicate elements

Can we overload the push_back() method in std::vector to allow non-duplicate elements? I know std::set and std::unordered_set are supposed to avoid duplicate elements, but std::set sorts the elements and std::unordered_set stores the elements in no…
argcv
  • 39
  • 6
1
vote
4 answers

C++ Vector string for-loop push_back error

I feel like this is a no-brainer, but for some reason I can't understand what's happening. When I run this part of my code, which is combining a URL with string elements from an array and then pushing that into a string vector, it pushes the first…
alyx
  • 2,593
  • 6
  • 39
  • 64
1
vote
2 answers

2 arguments in push_back

I am trying to put 2 arguments inside a vector using push_back but its giving me an error since the function is allowed to take only one argument. How can I pass 2 arguments?? Vertex Class: template class…
tech_human
  • 6,592
  • 16
  • 65
  • 107
1
vote
1 answer

Print Implementation fails right after pushback (vector)

I am new to C++ and vectors and so, I am facing some trouble with this function not printing the desired values after a push back. I am receiving what I believe to be garbage values. Could it be because I am working with unsigned char and not…
user10976719
1
vote
2 answers

How to create and use list, of type "customClass"

I have created a class "Node" to contain a bunch of data. I am trying to make a list of the same type of this class. I am having errors in trying to use push_back() or any of the other functions. error is the following:"…
Robin
  • 737
  • 2
  • 10
  • 23
1
vote
1 answer

Read Access Violation using Smart Pointers

I am trying to use push_back as part of a member function in class StrBlobm to add elements to a vector in a shared pointer also contained in StrBlobm, but I keep getting this error: Exception thrown: read access…
Mild Max
  • 37
  • 1
  • 8
1
vote
1 answer

Unexpected output: vector of vector (power set)

I am trying to write the solution to one of the problems of CTCI - Write a method to return all subsets of a set. However, I'm not getting an expected output. There seems to be a silly error but I'm unable to spot it. Below is the code: template…
code_art
  • 11
  • 3
1
vote
1 answer

a simple phonebook program push back contacts into the vector

I'm writing a simple phonebook program in c++ not using classes. I have a function which add a contact. I wonder why it doesn't work! it doesn't push back the contact into the vector I would be very thankful if you could help me. A peace of my code…
shirazy
  • 109
  • 3
  • 11
1
vote
5 answers

C++ vector - push_back

In the C++ Primer book, Chapter (3), there is the following for-loop that resets the elements in the vector to zero. vector ivec; //UPDATE: vector declaration for (vector::size_type ix = 0; ix ! = ivec.size(); ++ix) ivec[ix] = 0; Is the…
Simplicity
  • 47,404
  • 98
  • 256
  • 385
1
vote
3 answers

c++ what really happens when you push_back or push_front in a deque

I'm reading from here: http://www.cplusplus.com/reference/deque/deque/push_back/ for void push_back (const value_type& val); that val is a Value to be copied (or moved) to the new element. e.g. if val is an instance of a class, in which case…
user210528
  • 35
  • 1
  • 5
1
vote
3 answers

How to insert structure pointer into stl vector and display the content

I am calling a function in a loop which takes argument as structure pointer (st *ptr) and i need to push_back this data to a STL vector and display the content in a loop.How can i do it? please help. struct st { int a; char c; }; typedef…
Deepak
  • 47
  • 5
1
vote
0 answers

push_back doesn't work as I aspected

i got a strange things with vector.push_back ... i wrote inside a loop while(size = getSectionSize(inputFile) ){ data->at(k).resize(size*3) ; sizes.push_back(size) ; cout << "sizes at k = "<< k << " = " << sizes.at(k) << endl; double…
Marco Ghiani
  • 219
  • 1
  • 12
1
vote
0 answers

Access denied while trying to push_back to a list in a loop

While studying C++ and playing around with lists, I started experiencing some weird behavior, which I was able to isolate to the following piece of code: #include int main() { std::list ls; for(int i = 0; i < 10; ++i) { …
André Sampaio
  • 309
  • 1
  • 5
1
vote
4 answers

c++ push_back() a struct into a vector

I have a large file with coordinates and the WayIds. Which I stored in a vector with the following struct: struct SOne { double y, x, wayId; }; The file looks like this: 52.8774, 6.7442, 777 52.8550, 6.7449, 777 52.8496, 6.7449, 776 In my…
user8123891
  • 21
  • 1
  • 3