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

How to fix this C++ code with runtime error malloc: sysmalloc: Assertion

So the problem is that this code gives malloc error when run. The input I give is n = 2, x = 4. I think the problem is with vector pre because this happens when push_back is called. int n, x; cin>>n>>x; n = (1< taken(n,…
Salmaan
  • 31
  • 8
0
votes
2 answers

How Vector allocation using push_back() and pop_back operation gives garbage values

I am solving a problem in which I have to find those element from the array whose total gives maximum sum. But there is a condition that no two adjacent element can be the part of that max subarray. Here is my code using simple brute Force…
T.g
  • 169
  • 2
  • 11
0
votes
1 answer

Confused with loop and mutate vector in c++

#include #include using namespace std; int main(int argc, const char *argv[]) { vector v{0, 1, 2, 3, 4}; for (auto it = v.begin(), e = v.end(); it != e; ++it) { const int x = *it; cout << x << endl; …
Xiong chenyu
  • 135
  • 1
  • 9
0
votes
2 answers

Help with constructor (pusing_back elements into a pointer to an array)

I have a problem inserting elements into a pointer to a vector of some elements I defined in my code (in this case Recipes). In some other parts of the code, using push_back seems to work fine, but if I use it in this code: { Recipe…
Jota
  • 234
  • 2
  • 11
0
votes
2 answers

C++ variable not passing it's value after push_back

I'm having a weird issue where the variables i'm declaring that are pushed back to a vector> are not being actually pushed back... Take a look: vector Lignetemp; for(int j = 0; j < InfoSup.nbL; j++){ Lignetemp.clear(); …
Falanpin
  • 55
  • 12
0
votes
1 answer

Union of two std::vector Read Access Violation

I have a union of two std::vectors and when I call push_back i get a read access violation. I'm pretty new to unions so I bet I'm doing something wrong with them. Any ideas why this is happening? struct Row { char order_id[30]; char…
R. Binter
  • 221
  • 1
  • 8
0
votes
1 answer

Appending a value to a nested QList

I am trying to append values to a QList inside another QList but it doesn't seem to work? Here is a MCVE of my problem where I try to append int values: #include #include int main(int argc, char *argv[]) { QList>…
Matt
  • 15
  • 7
0
votes
1 answer

When i try to define this vector< pair< int , pair > > vp(n)

There's in output Give me 0 0 #include #define fsv(i , n) for(int i = 0 ; i < n ; ++i) using namespace std; int main() { int n ; cin >> n ; vector< pair< int , pair > > vp(n); vector v(n) ; fsv(i ,…
0
votes
2 answers

How to set up vector of vector pairs?

In this code, I am trying to make a vector of vector pairs. The code compiles but it has a segmentation fault and I cannot figure out where I am going wrong. I would be grateful for any hint that can solve my problem. #include #include…
user143
  • 19
  • 5
0
votes
0 answers

cv::Mat pushback to std::vector issue

The goal is to read images from a basler camera (with pylon) to opencv matrix, and load that in a std::vector container with the push_back() method. My attempt fails as all the saved elements will be the last one. So if I push back 295 element, all…
Dániel Terbe
  • 105
  • 1
  • 10
0
votes
1 answer

Vector Stack Pair | Longest path in a tree using dfs

#include using namespace std; vector adj(10001); bool vis[10001]; void initialize () { for (int i = 0; i<10001; i++) vis[i] = false; } pair dfs ( int x ) { stack < pair > s; s.push(…
0
votes
1 answer

What explains so many moves and destructions in this snippet

In order to understand the rule of five, I came up with this: #include #include class A { public: A(int y) { std::cout << "constructed\n"; x = new int[y]; } ~A() { std::cout << "destructed\n"; delete[]…
0
votes
3 answers

vector within vector generates duplicate values in second dimension

In the example below (which can also be seen in Ideone), I have a vector of a class and inside the class I have an element also vector. The problem is that when doing the push_back of the class, the internal vector vetint should start from the…
Rogério Dec
  • 801
  • 8
  • 31
0
votes
2 answers

Writing my own push_back funtion

I have a simple c++ phonebook project, and I'm no allowed to use std::vector. So i decided i create one for myself. And I'd like to ask a little help about my push_back function. So this is in the vector.h: class Vector{ int siz; …
0
votes
2 answers

C++ Out Of Range When using Vector

So I have created a Binary Search Tree (BST) by placing nodes into a vector. These nodes store 3 values, a user input int ID, a user input int age, and a user string input name. When inserting these nodes into the vector, they are stored going in…
Granzo
  • 59
  • 1
  • 7