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

C++ -- Adding elements to private member field std::vector

class T { private: std::vector myVec; // ... public: T(); T(float x, float y); std::vector getMyVec() { return myVec; } // ... }; // in T.cpp I don't use myVec in any way (not in the constructor either) // in Tmain.cpp: int…
Beko
  • 982
  • 3
  • 15
  • 26
0
votes
2 answers

vector insert vs push_back performance issue

When I profiled my program, I discovered a bottleneck at: for (int i = 0; i < len; ++i) { vec->push_back(buffer[i]); } The for-loop lies in a function which is called 100k times. After replacing it with the following code, the performance…
Radu
  • 384
  • 4
  • 15
0
votes
2 answers

I can't seem to get v.push.back() to work with strings

// ConsoleApplication25.cpp : main project file. #include "stdafx.h" #include #include #include #include #include #include using namespace System; using namespace std; int main() { …
Fox
  • 3
  • 2
0
votes
3 answers

push_back() in vector of a Point doesn't work

I have a problem with pushing a class Point into a vector. I have a class Point: Point::Point(){ this->X=1000; this->Y=1000; } Point::Point(int x1, int y1){ this->X = x1; this->Y = y1; } I create a vector like this: vector
user3314570
  • 237
  • 4
  • 14
0
votes
2 answers

Vector does reallocation on every push_back

IDE - Visual Studio 2008, Visual C++ I have a custom class Class1 with a copy constructor to it. I also have a vector Data is inserted using the following code Class1* objClass1; vector vClass1; for(int i=0;i<1000;i++) { …
infinity
  • 1,900
  • 4
  • 29
  • 48
0
votes
1 answer

Error with Push_back function for a LinkedList?

So, I've been working on a linked list pushback, and every time, I get some weird output, can someone help see what I'm doing wrong? void IntList::push_back(int ne) { if(head == NULL) tail = head = new IntNode(ne); IntNode *nes = new…
Marksman46
  • 19
  • 7
0
votes
1 answer

pushing back data into 2d vector in c++

vector col(0); vector > row(0); for(i=0;i<10;i++) col.push_back(some integer); row.push_back(col); col.clear(); Can someone tell me what is wrong here? In the col[] vector, there is no error, but when I go to the next…
asker
  • 15
  • 1
  • 2
0
votes
0 answers

Vectors in c++ is giving error segmentation fault while performing push_back? code is attached.!

segmentation fault is occurring just after the push_back in the first loop. #include #include using namespace std; vector a; int main() { int i,n,k,q,temp; cin>>n>>k>>q; for ( i =0;i>temp; …
0
votes
1 answer

Problems with push_back in a vector

I'm creating a graph class in c++ but having some problems to insert elements into it. The graph is implemented using a vector > simulating a linked_list. Here is my main.cc: http://pastebin.com/xkamm7Jq #include #include…
Guilherme
  • 443
  • 5
  • 22
0
votes
0 answers

vector.push_back is not resulting in the right value being pushed back

I am practicing merge sort (for interview prep purposes). I am running into a very strange issue with vectors. It seems that pushing a certain value back onto the vector does not result in that value actually being put there. I could be missing…
ahmedalishaikh
  • 113
  • 1
  • 2
  • 6
0
votes
2 answers

array instead of vector of vector, push_back() of elements. c++

I use approach of vector of vector and would like to change it into array for performance reasons. However I failed at trying to understand, how can I use array (dynamic) and push data in the end of the array, if I do not know how many data are…
beginh
  • 1,133
  • 3
  • 26
  • 36
0
votes
1 answer

Updating the size of a vector of pointers using push_back inside a function class

I´m having a problem using push_back of a vector of a class inside a function class. My codes are [All variables are in Portuguese, sorry]: My Main: int main(int argc, char* argv[]) { //blah blah before here... vector
0
votes
1 answer

C++ vector.push_back crashes after pointer definition

my C++ compiler behaves very weird. My vector is defined globally: vector values; This does not cause any error: void locate( int r, int s, bool newCheck, int from = 0 ){ static int A = 255; static int U = 1; static int D = 2; static int R =…
Milos9304
  • 3
  • 1
0
votes
1 answer

Singleton + nonstatic member - How to

class Scheduler:public Kolejka { private: unsigned long real_time; Scheduler(void) :real_time(0L){} Scheduler(const Scheduler &); Scheduler& operator=(const Scheduler&); ~Scheduler() {} public: std::deque kolejka; //... …
Hrabia
  • 19
  • 7
0
votes
1 answer

segmentation fault during push_back

I'm getting a very weird segmentation fault on the following loop. The goal is to have each processor do some checks of x/y points which are stored on the following vectors Just to clarify: This is a multi-processor code not multi thread. This is…
giorgk
  • 109
  • 1
  • 11