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

Vector push_back of one object results in a vector of enormous size

i'm working on a project in c++, and I have a vector of objects, where I want to push_back an object on the existing vector. However, when checking the size before and after the object is added, the size goes from 0 to 12297829382473034412 which…
Scartzaw
  • 21
  • 2
2
votes
1 answer

Dynamically adding a row to a std::string 2d vector array

I'm trying to create a dynamic 2d std::string vector but having trouble adding the new rows: std::vector> hops_vector; int Hop = 0; for (Hop = 0; Hop < RouteHops; Hop++) { char HopIPString[20]; HopIPString[0] = 0; …
Dan
  • 2,304
  • 6
  • 42
  • 69
2
votes
0 answers

C++11 noexcept doesn't affect "copy/move" choice in VC. Is this a VC bug?

[Effective modern C++]says, vector::push_back will allocate new memory block when capacity is not enough,and then "copy or move" elements to the new block Whether to choose copy or move depends on a class A's move ctor having "noexcept" or not.…
Hind Forsum
  • 9,717
  • 13
  • 63
  • 119
2
votes
1 answer

Implementation of push_back and pop_back

I want to understand how std::vector::push_back and std::vector::pop_back create and destroy objects in an allocated memory ? I used google and all I find is people just play with size and capacity to limit the access to the internal…
Laith
  • 1,248
  • 2
  • 11
  • 19
2
votes
2 answers

Appending an item to a vector copies all previous items

In the following code, I would expect that the copy constructor of A is never called, as the items should be created directly at the vector with emplace_back and then the total result should be return-value-optimized. This seems to be the case.…
Zah
  • 6,394
  • 1
  • 22
  • 34
2
votes
2 answers

vector push_back over std::copy

I have a function which has an unordered set as a parameter . Since I am using openmp I am converting this unordered set to vector . I use a std::copy for this conversion . //pseudo code func( std::unorderedset s1) begin vector v1; …
sameer karjatkar
  • 2,017
  • 4
  • 23
  • 43
2
votes
2 answers

STL push_back: previous values getting modified when pushing a dynamically changing array

I am having a very strange problem with std::vector.push_back() in my CPP code. Basically, all I am doing is: void func() { if(first_time_coming_here) { do_some_stuff(); V.push_back(Mat::zeros(3,1,CV_32FC1)); // OpenCV Mat structure …
HighVoltage
  • 722
  • 7
  • 25
2
votes
2 answers

Push Back in Map

Is there any possibility to use push_back() in maps? I want to make a map < int, vector> and fill the vector in a loop with strings. It should look something like this: map[int] = vector.push_back(string);
Eppok
  • 55
  • 1
  • 7
2
votes
1 answer

Qt containers with object

When using a Qt container as Qlist, Qvector etc to hold some class (say a complex class with many data members and logics) and calling insert/append/push_back will the object added to the container be inserted to the container or it will be copied…
ClimbingLung
  • 219
  • 2
  • 8
2
votes
2 answers

How to use vector iterators when using vector<>::push_back()

For simplicity, I'll stick to vector but I think this applies to any vector object. If I am using a vector::iterator to keep track of some position in a vector of int's and then I use vector::push_back(), the iterator becomes…
kilgoretrout
  • 3,547
  • 5
  • 31
  • 46
2
votes
3 answers

PushbackInputStream and mark/reset

I use PushbackInputStream to look ahead the next byte in a stream (bufferedIn which is a BufferedInputStream) because I want to mark() before some value, and later to rewind prior to it using reset(). // Wrap input stream into a push back…
mins
  • 6,478
  • 12
  • 56
  • 75
2
votes
1 answer

std::vector's push_back() causing a strange compile-time error message

My snippet of code: void RMWavefrontFileImporter::loadVertexIntoVector( const std::vector lineElements, std::vector* vertices) { assert(vertices); std::unique_ptr verticeRef =…
diegoreymendez
  • 1,997
  • 18
  • 20
2
votes
1 answer

Problems when using repeated push_back() to initialize a vector

Problems using repeated push_back() to initialize a vector So in my program, I have a struct containing only doubles and double arrays: struct Particle { double x[2]; double v[2]; double pressure; ....... }; When I initialize one of…
2
votes
1 answer

Vector push_back causing Unhandled exception

Everything is working until the compiler tries to perform the push_back operation. in the if condition proper values are being returned. I have declared items as: vector items; // inside the header file. //inside the .cpp file void…
Adroit
  • 701
  • 1
  • 6
  • 18
2
votes
3 answers

C++ Vector of classes, can't push_back inside constructor of said class

So here is my problem, I want a vector of objects of a certain class that I can then pass to other classes for use. I want the Vector to add an instance of the class within the constructor of that class. So I've set up a static vector inside the…
Louden100
  • 53
  • 2
  • 5