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

Memory taken by a vector of vectors

What is the expected difference (if any) in memory taken by vvint1 and vvint2? Is vitest1 copied into a new memory position each time a push_back takes place? Is vitest2 copied into a new memory position each time a push_back takes place? typedef…
0
votes
2 answers

When it comes to a sequence, is "vector[n].push_back()" is always O(1)?

I've used vector v[N] a lot. It's a very powerful tool for me. I wonder v[n].push_back() costs O(1) on average. I know when the vector is full, it needs to expand into double. But isn't the sequence of vectors attached to each other? If so, I…
marks jun
  • 25
  • 4
0
votes
0 answers

How to display all elements in vector

When I try to display all elements in the vector, it only display name of dealer, and number of dealer, but number of cars is MISSING! So how do I display the whole vector completely? I declare a vector in Main and pass it to the readIn and display…
Lin
  • 1
0
votes
1 answer

Execution is halting at push_back

The following for loop halts execution at the first cycle, and I have no clue why. I have figured out by placing couts in it that it stops at the push_back. It was working before, then I tried modifying it, then I did Ctrl-z to get it back to this…
sqrtoiler
  • 13
  • 2
0
votes
0 answers

Can anyone explain why push_back() causes a SEGFAULT here?

I've been getting a segfault and I narrowed down where the issue comes up by simplifying my main() function and using valgrind. main.cpp int main() { unique_ptr g1 = make_unique(); unique_ptr g2 = make_unique(); …
Nick Nagy
  • 61
  • 4
0
votes
1 answer

Copy constructor get called more than one time

Below code outputs: Default ctor is called Copy ctor is called Default ctor is called Copy ctor is called Copy ctor is called Why for each push_back() the calling of copy constructor incremented by 1? I think it should only be called one time. Is…
Islam Abdeen
  • 539
  • 3
  • 10
0
votes
1 answer

Implement a class want to simulate std::string but get stuck when push_back it into a vector

I have implemented a class String. When I push_back a String object to a Vector, the program gets stuck. Please help me review it if you're interested. String.h #pragma once #include #include #include class String…
Zhen Yang
  • 83
  • 9
0
votes
0 answers

C++: push_back() function doesn't append double values: segmentation core dumped

I am having trouble with the push_back() function in C++. For a reason which I don't understand, the push_back function will "not accept" the value I am telling it to append, but the code works perfectly until I try to display the values I want (end…
Joachim
  • 490
  • 5
  • 24
0
votes
1 answer

free(): invalid next size (fast) for resizable vector

I'm trying to implement a resizable vector in C without using the realloc and calloc functions. However, when I try to push a lot of values to the back of the array, I get a free(): invalid next size error. How can I remedy this? I tried freeing the…
bamfot13
  • 1
  • 1
0
votes
3 answers

I'm having difficulties splitting a string into a vector

I'm trying to write code that initializes a string into a vector by splitting it at every space character. Somehow the temporary vector won't take the positions and it doesn't split the string right. #include #include #include…
Demonic-Coder
  • 21
  • 1
  • 3
0
votes
1 answer

List items and iterators: do either push back or iterators create copies of original data?

Though I've a lot of experience as C Embedded Programmer, I'm actually not so skilled in C++. I'm implementing a parser in which ItemsToBeFound are pushed within a list. It happens that some of these items (let's say master items) carry more…
Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
0
votes
2 answers

Why does push_back into vector> causing seg fault?

Want to construct a Graph with adjacency list, but getting seg-fault when I add elements to vector>. adj.size() prints 5 which tells it has allocated memory, why the seg-fault in addEdge() method? #define V 5 struct Edge { …
a k
  • 531
  • 5
  • 15
0
votes
2 answers

Issues related to user input array elements in one line in c++

I am coding a very basic problem but I am stuck in reading input of an array in one row. I have used the technique used mentioned in How to user input the array elements in c++ in one line but I see that it doesn't work and it gives 'segmentation…
Hamsa
  • 476
  • 5
  • 23
0
votes
0 answers

How can I add row or col in the left of the matrix?

I know how to add row or col in the right of the matrix: cv::Mat row = cv::Mat::ones(1, 3, CV_64F); // 3 cols, 1 row m.push_back(row); // 3 cols, 5 rows But I don't know how to add row or col in the left of the…
user11690510
0
votes
2 answers

Push_front and push_back methods for linked list seems to remove a node

I'm writing a class called Playlist which performs different operations on PlaylistNodes. I looked online and tried to implement push_back and push_frontmethods, but I was unsuccessful. PlaylistNode *PlaylistNode::insert_next(PlaylistNode *p) { …
MZP
  • 51
  • 1
  • 5