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

C++ push_back compiler error "

I am trying to add a struct to a vector of structs. vector n; vector_tags; for (unsigned t=0;t<_tags.size();t++) { udtTag &nt=_tags[t]; for (int i=nt.PosStartTag;i
tmighty
  • 10,734
  • 21
  • 104
  • 218
0
votes
1 answer

C++ Cannot use push_back on list containing custom structs

We are making a list that hold info on boardgames (name, year, score). We scan the info out of a .csv file, make a struct based on that info and then add the struct to a list. We keep doing this untill the document is done reading. Problem is that…
Emvidasch
  • 97
  • 1
  • 7
0
votes
0 answers

Vector of lists fails to copy new element

My goal is to find the shortest paths from each node in a graph to each other node via Dijkstra's algorithm, including equal length paths that are different from each other. To store these paths, each node has a vector for each other node in the…
forley
  • 1
  • 1
0
votes
0 answers

C++ push_back overwrites last vector element

Since I cannot answer my own question in 8 hours after asking, I'm posting my solution here. Made some mistakes in the incoming channel number and number of the vector element. Setting the value of channel-1 instead of channel fixed to problem. My…
0
votes
1 answer

std::sort() not working on vector of pairs

I have the following code snippet: struct compare { bool operator()(const pair& left, const pair& right) { return left.second > right.second; } }; int main() { size_t vertices = 31112738; …
user1715122
  • 947
  • 1
  • 11
  • 26
0
votes
3 answers

How do you add new objects to a user-defined Class vector?

I'm a C++ beginner (no prior programming experience). I'm writing a text-based game and I have a core module to develop for the "Population" of the game. So far I've established the population growth rates (based on pre-defined natality and…
Optimae
  • 942
  • 1
  • 12
  • 23
0
votes
1 answer

c++ vectors and push_back

I am getting a strange c++ error: main.cpp:81:9: error: request for member ‘push_back’ in ‘points’, which is of non-class type ‘std::vector >()’ I am reading this like c++ is trying to tell me that the function push_back is not…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
0
votes
6 answers

Push_back doesn't work

Tried on Visual 2010, Visual 2012 and CodeBlocks without success. I've been roaming the internet for an answer for the past 3 days and have found nothing to help me. I've tried two ways, first vector mvec; int num; while(cin >>…
0
votes
1 answer

time complexity of reserve on an empty vector vs. a deque and whether to use emplace or push_back

I am debating which is going to be faster, if I am using a data structure to store call backs within a class should I use a vector and reserve on start up or should I just use a deque in this case since the total number of subscribers is not known…
bjackfly
  • 3,236
  • 2
  • 25
  • 38
0
votes
2 answers

Generic Vector Push Back Template

I'm writing some code to interact with a database. My solution is to use vectors of various structs to represent each table within the database. I want to create a template inside my Database class to push_back the vector and insert a new (blank)…
Ash
  • 3
  • 2
0
votes
1 answer

C++: Eclipse code checker error related to vector push_back

The code: #include int main() { std::vector v1 = {12, 34}; std::vector v2 = {56, 78}; //Doesn't work. v1.push_back(v2[0]); //Works. int i = v2[0]; v1.push_back(i); return 0; } For some reason,…
0
votes
2 answers

Push_back in vector of objects from aggregate class

I'm having a little issue with vectors. From what I understand, push_back() will copy the argument and insert the copy in the vector. struct BridgeData { string name; string type; }; For a simple aggregate class such as mine, the copy of an…
wrousseau
  • 311
  • 3
  • 12
0
votes
0 answers

SIGTRAP on push_back with vector, no breakpoints set

I am trying to generate a spanning tree of a graph by using a randomized version of Prim's algorithm. However, my program crashes during the spanning tree generation phase, and closer examination has revealed three different errors. 1) A SIGTRAP is…
Nelarius
  • 181
  • 2
  • 10
0
votes
1 answer

Simple Calling vector of a class I made "does not name a type"

Quick intro I am having an issue when I define a simple class called 'token', that is comprised of two int values, and I make a vector out of this class. I am unable to use the 'push_back'. the compiler tells me my 'does not name a type' Code…
Krtko
  • 1,055
  • 18
  • 24
0
votes
2 answers

Memory allocation with vector push_back

I learned something interesting today: if I have a standard vector v and I run code like: std::vector v; for (int i = 0; i < 2; i++) v.push_back(2.); if I call v[2] I will not get a segmentation fault, because the operator[] does not do…
webb
  • 450
  • 1
  • 3
  • 12