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

Vector.push_back Issue

The following question concerns the use of a vector and memcpy. Vector functions being used are, .push_back, .data(), .size(). Information about the msg. a) #define BUFFERSIZE 8<<20 char* msg = new char[(BUFFERSIZE / 4)]; Question: Why doesn't code…
Jesper
  • 11
  • 1
-3
votes
2 answers

C++ Vector elements being replaced by last call to push_back

So I have this code in my main function if(mesType == 1) { cin.ignore(); Message mes1; stack1.push(&mes1); } else if(mesType == 2) { cin.ignore(); MorseCodeMessage mes2; stack1.push(&mes2); } and here…
Caleb lee
  • 43
  • 7
-3
votes
2 answers

how to use push_back in vector of a struct

hey guys i have created a struct node. one of its fields is a vector (path) where i want to store characters.however when i try to push_back a character the compiler says "error: ‘path’ was not declared in this scope" #include #include…
-3
votes
1 answer

How to get push_back to work in C++ program

I'm working on a C++ assignment and having some issues with an error in regards to push_back. The error message reads: No matching member function for call to 'push_back'. The error occurs at the line that reads:…
John Smith
  • 13
  • 1
  • 2
-3
votes
1 answer

2d vector says class does not have member named push_back

ManageShips::ManageShips(vector< Spaceship > itemShip, vector< Spaceship > personShip, vector< Item > itemCargo, vector< Person > personCargo){ m_itemShips =…
Nabil Hassan
  • 43
  • 2
  • 6
-3
votes
3 answers

what the output is always zero even if i use push_back in stl c++?

push_back doesn't add the value of i to the vector n in the following code: #include #define _ ios::sync_with_stdio(0);cin.tie(0); using namespace std; /*macros*/ #define fi(i,a,b) for(int i=a;i
mr-woot
  • 88
  • 1
  • 10
-3
votes
1 answer

vector::push_back ( A * ) creating leaks?

I'm trying to create a really simple virtual filesystem (represented as a tree)(for my FTP server) mapped to several places on my real one. Nodes are represented by a Node object which holds pointers to its contents in a vector. I know that for…
Lea
  • 211
  • 1
  • 2
  • 14
-3
votes
1 answer

Segmentation fault using Vector C++

I am trying to separate all the values stored in a vector into two different vectors. But when i am printing value of any of the vectors it is throwing seg fault. Below is the code sample. std::vector V,Vx,Vy; for (int i = 0; i < k;…
sandyroddick
  • 77
  • 4
  • 16
-4
votes
3 answers

Why can't I use push_back function?

void Add(vector< vector > &name, vector< vector > &author, vector< vector > &pub, int &total_books) { Line(); string book_name,book_author,book_pub; cout << "Please enter the book name:…
KYUNGWAN RYOO
  • 11
  • 1
  • 2
-4
votes
1 answer

Vector push_back inserting 0s only

int main() { long int n; long int k; long int q; long int o; long int temp; cin >> n >> k >> q; vector a(n); vector b(n); for( int a_i = 0;a_i < n;a_i++){ cin >> a[a_i]; } for(long…
S___V
  • 5
  • 2
-4
votes
2 answers

How do I parse a line into pieces and ignore parts of it?

I am sorry. I wasn't clair previously. I have a file that include data in the following format A(3) B(4),A C(2),A E(5),A G(3),A J(8),B,H H(7),C,E,G I(6),G F(5),H ... These data represent a graph. I will use the critical…
DrD4rk
  • 57
  • 1
  • 11
-4
votes
1 answer

R-value Reference push_back Function

I'm writing a Queue class. I have two versions of push_back for the new C++11 standard. One of these versions uses a rvalue reference as a parameter. My version works, but I think it must be lacking something: 97 template 98 void…
Victor Brunell
  • 5,668
  • 10
  • 30
  • 46
-4
votes
1 answer

How to use push back method for a C++ vector

int numFiles; cout << "How many signal files are there?"; cin >> numFiles; vector signalFiles(numFiles); vector backgroundFiles(numFiles); string backgroundFile; for (int i=0;i
Channing
  • 166
  • 1
  • 9
-5
votes
2 answers

C++ How to represent a string in binary format?

For some reason, I need to frequently generate strings use characters in {'0', '1', '2', '3'}. My current code use push_back() function and looks like: string test = "" test.push_back('0') test.push_back('2') test.push_back('3') // test would be…
-9
votes
1 answer

Why can't I directly push_back update value from function in vector?

push_backing to a vector with function updated values doesn't permit why? std::vector< std::string >goin; goin.push_back(function(somestringvalue)); // why cant it take update value? void function(std::string& var) { var += "pre"; }
rosti
  • 1
  • 4
1 2 3
27
28