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

Updating vector of class objects using push_back in various functions

I have a vector of class objects I've created in main by reading in a data file. I'm then passing around the vector to several different files containing functions that perform different operations on the vector (sorting by different fields,…
Evan R
  • 875
  • 13
  • 27
3
votes
2 answers

Filling of vector with unique_pointers

I have to classes A and B. B derives from A. I have also vector std::vector> samples This piece of code works: std::vector> samples; samples.push_back(std::make_unique(param_1, param_2)); But this one…
rainbow
  • 1,161
  • 3
  • 14
  • 29
3
votes
3 answers

map > > pushing back into pair?

I have this map > > variable and I'm pushing back a value, but code::blocks is telling me that pair does not have a member function called push_back. What should I do to get it to push back pairs rather than…
calccrypto
  • 8,583
  • 21
  • 68
  • 99
3
votes
3 answers

Using push_back on a vector of strings - C++

I am trying to use push_back on a vector of strings in C++. How can I push a single character on to the vector? Currently, I have tried the following, all without success: Initialized a string (tried to) with the character. Code string…
Sriram
  • 10,298
  • 21
  • 83
  • 136
3
votes
2 answers

Push back data into a 2D vector

I am trying to create a 2d vector of set size and then insert data into it. The issue I am having is being able to insert the data filling up each column and row in the 2d vector. I have read through various other threads, but cannot find an…
Nezz609
  • 33
  • 6
3
votes
2 answers

How to reduce the temp object when using push_back and getline?

I found an example about how to use std::getline(), and this is the code snippet: std::istringstream input("abc|def|gh"); std::vector> v; for (std::array a; input.getline(&a[0], 4, '|'); ) v.push_back(a); We can…
Kevin Dong
  • 5,001
  • 9
  • 29
  • 62
3
votes
2 answers

push_back operation in c# containers

I need container like c++ vector. Often it is adviced to use List, but it dosen't support push_back operation. I know this is rather simple implementing an extension method for List container. But. Would Stack be a good alternative? Thanks!
lexeme
  • 2,915
  • 10
  • 60
  • 125
3
votes
6 answers

Faster alternative to push_back(size is known)

I have a float vector. As I process certain data, I push it back.I always know what the size will be while declaring the vector. For the largest case, it is 172,490,752 floats. This takes about eleven seconds just to push_back everything. Is there a…
anc
  • 191
  • 1
  • 19
3
votes
3 answers

How exactly do I use the functions push_back and pop_back()? I looked them up in the following liks but still don't understand

http://www.cplusplus.com/reference/vector/vector/push_back/ (C++11 Version) What is the difference and/or advantages of void push_back (const value_type& val); & void push_back (value_type&& val) and which do you suggest I use?; I don't understand…
Gulp Dragondawn
  • 101
  • 3
  • 10
3
votes
3 answers

Benchmarking adding elements to vector when size is known

I have made a tiny benchmark for adding new elements to vector which I know its size. Code: struct foo{ foo() = default; foo(double x, double y, double z) :x(x), y(y), z(y){ } double x; double y; double z; }; void…
Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
3
votes
2 answers

How to insert after the last element of a resized std::vector?

I know how much space I initially need in a std::vector. So I use .resize() to set the new vector to that size. But when using .push_back() afterwards, it adds the elements at the end of the allocated size increasing it by one. How can I add new…
danijar
  • 32,406
  • 45
  • 166
  • 297
3
votes
2 answers

deque insert invalidation of iterators vs. pointers ( references)

Based on citation from cplusplus.com If the insertion happens at the beginning or the end of the sequence, all iterators related to this container are invalidated, but pointers and references remain valid, referring to the same elements they were…
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
3
votes
1 answer

How to push_back an integer to a string?

Right now, I'm preparing to do a homework assignment by first sorting out what I'm going to do in my methods. For one of them, I have to prepare a list of names to be added to a list in the form A1, B2, C3 ... etc. What I am testing right now is a…
assignment_operator
  • 1,213
  • 4
  • 12
  • 14
3
votes
2 answers

vector.push_back

I am writing an application that reads from data files of a given format. In the file, I've dynamically created a 2D array of pointers to vector objects. Basically, it reads through the file, and when it finds a given string pattern, it stops and…
naxchange
  • 893
  • 1
  • 11
  • 24
3
votes
3 answers

Pushing pointers into c++ vectors, and cleanup

I am converting some code between different systems, and I have a question regarding c++ vectors. If I do something like this: In header file: struct Vertex { float x; float y; float z; } struct submesh { Vertex…
Dan D'Man
  • 33
  • 1
  • 4