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

Is there a way to add names of 5 students with 3 exams scores each to a vector?

I am lost again, I know that there is a way to use push_back to add to the vector, but I am at a loss for how I can actually get it to work. What I am trying to do is add 5 students to a vector (Egrades), and with each student gather 3 separate exam…
Pierce2307
  • 41
  • 2
0
votes
1 answer

push_back copy objects even for temps although stating otherwise in it's definition?

one of push_back definition is push_back(const value_type& __x) so Having my_vector2.push_back( obj ); will result in passing object obj by reference( No copy during passing object) still it call the copy constructor in the body of push_back…
KMG
  • 1,433
  • 1
  • 8
  • 19
0
votes
1 answer

Troubles with inserting elements in dynamic array in C

I have a dynamic array with this struct: typedef struct vector_struct { size_t e_sz; char e_type; #define V_INT 1 #define V_DOUBLE 2 #define V_CHAR 3 #define V_FLOAT 4 unsigned no_e; unsigned cur_cap; void* e_array; }*…
0
votes
2 answers

Pushback elements of other arrays

I created two arrays A and B, the array C should store the first elements of A and B. Ex : A={1,2,3}, B={4,5,6}, C must be {1,4,2,5,3,6}. My program doesn't show anything after the input of my arrays. This is my loop : for(int i(0);i<3;i++){ …
Hibou
  • 196
  • 2
  • 3
  • 10
0
votes
2 answers

Using "push_back" for vector with "get" function C++

I have a class called "Region", and I have a class called "Map". The "Map" class has a vector of type "Region *" called "regions" as a member. In the .cpp file for the "Map" class, I have a "getRegions" function that returns this "regions"…
wolfeweeks
  • 355
  • 4
  • 12
0
votes
1 answer

The program is not collecting data from csv file?

#include"std_lib_facilities.h" void login(){ fstream fin; fin.open("user.csv",ios::in); vectordata; string word; string temp; string line; while(fin>>temp){ data.clear(); getline(fin,line); stringstream s(line); …
Sree Hari
  • 17
  • 5
0
votes
0 answers

push_back using raw pointers vs using smart pointers

I am having trouble understanding how to create new objects of a class and push it into a vector using smart pointers. using raw pointers it would look something like this: std::vector creat_cards; // vector with the objects std::vector…
konoha
  • 57
  • 1
  • 8
0
votes
2 answers

Linked Lists (very intro) InsertBack

#include #include struct node { int data; struct node *next; }; typedef struct node node; node* insertFront(node* head, int d); node* insertBack(node* head, int d); void print(node* head); int max(node* head); int…
0
votes
0 answers

vector push_back after curly braces initializer does not work in C++

I have a vector with {} initializer. And then I use push_back to add an element into the vector. When I print the vector elements, the pushed element does not print. Why is that? int main() { vector vec = {0,1,2,3,4,5,6,7,8,9}; …
Yun Li
  • 407
  • 1
  • 5
  • 13
0
votes
1 answer

Segmentation fault when trying to push to either an int stack or vector in C++

right now I'm trying to solve a competitive programming problem but whenever I try to push to a vector (bb), it gives me a segfault. I've tried fixing this by switching from stack to vector and by just attempting to push a regular integer with no…
Xiao
  • 17
  • 1
0
votes
2 answers

Implementing push_back(T&& c) in custom Vector class

As part of an assignment in Uni I have to implement a partial clone of the stl::vector class. I've managed nearly all the functionality but I am stumped with how to do push_back(T&& c). We're not allowed to implement emplace like STL itself uses.…
Daniel
  • 33
  • 1
  • 5
0
votes
0 answers

Data archive saving - Process returned -1073741819 <0xC0000005>

I'm having some trouble. After coding a full oriented object programming on C++, I'm trying to save the data in a archive, to use it again every single time that the program opens. In the first line, it is confirmed: "Student Daniel Cassiano has…
0
votes
1 answer

Why behavior changes as order of a emplace_back / push_back changes ? Why number of Constructor increases?

class Buffer { unsigned char* ptr{nullptr}; size_t length{0}; public: Buffer() : ptr(nullptr), length(0) {std::cout<<"\n In Buffer()\n";} explicit Buffer(size_t const size): ptr(new unsigned char[size] {0}), …
0
votes
0 answers

How do I use strings with vectors in vectors (2D Vectors?)

I'm trying to create a vector that has vectors inside it, but I'm dealing with string and cin My goal is to ask the user to list out student names, and for each student listed, a vector will be created under "stuNameVecs" vector. Then these…
Ahed N
  • 1
0
votes
1 answer

Why am i getting an overlad error when using .pushback on vector enclosed by a vector

I'm trying to create a hash table with a vector inside a vector made of a struct. v[1].push_back(value); it's giving me an error: error C2664: 'void std::vector>::push_back(_Ty &&)': cannot convert argument 1 from 'int' to…
Boarn
  • 3
  • 2