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

C++ Vector of Struct using push_back

This is an assignment for a course that I am having problems with. Until now I thought I was fairly familiar with vectors in C++. This program is supposed to take a file from the user calculate the users pay then spit back out in a nice table all…
GenCrash10
  • 9
  • 1
  • 5
-1
votes
3 answers

vector function "push_back" keeps rewriting the value to the same slot in memory

The push_back method of the std::vector isn't putting the second console input in the v[1] slot, it keeps overwriting it in the v[0] I tried to search for other answers to this but the code and answer is too complicated for me to follow, im trying…
donnie
  • 17
  • 1
  • 7
-1
votes
3 answers

How to define the function push_back to an Arc struct?

I am fairly new to C++ and I don't know how to define the function push_back to my struct: struct Arco { int i, j; Arco () {}; Arco (const Arco& obj): i(obj.i), j(obj.j) {}; Arco(int _i, int _j) : i(_i), j(_j) {} }; I have a…
rbl
  • 17
  • 6
-1
votes
1 answer

Error with std::vector push_back

I am trying to use the std::vector push_back method to insert Node objects into a vector that stores template Node objects. The error I am getting I believe is saying that the input I am using for the push_back method is not the correct type? Can…
user2932450
  • 71
  • 1
  • 2
  • 12
-1
votes
1 answer

Strange (memory?) issue with std::vector.push_back()

I have a function getfafr(N,n,twoq) that returns a 3-dimensional tensor fafr in the form of std::vector > >. It does not have uniform size (i.e. fafr[i][j].size() can be different for different i,j etc), which is implemented using…
jorgen
  • 3,425
  • 4
  • 31
  • 53
-1
votes
2 answers

Pointer to object in a class: push_back and pointers conflicts

I have several problems with a code which has a similar structure to this one shown. It doesn't work! I think the main problem is the push_back function, that I need for other scopes (I need to build a vector of classes during the operations, and…
The Newbie Toad
  • 186
  • 2
  • 15
-1
votes
5 answers

Having trouble adding an element to a string vector

I'm writing a simple journal like function, however I can't seem to fathom out how to generate a new element of the vector by passing the value the user enters. I am new to programming so the answer might well be obvious :/ I get no errors when I…
Iskardes
  • 45
  • 5
-1
votes
1 answer

C++ code crashed when using vector push_back in RELEASE configuration

I have a problem using c++ vectors when I build the solution in release configuration by Visual Studio 2008. The code works fine in Debug configuration. I have searched online and did not find a solution that solves the issue that I have. Here is…
afp_2008
  • 1,940
  • 1
  • 19
  • 46
-2
votes
2 answers

push_back() not working for custom data type (template class)

Apparently push_back() is not working for my custom data class T. On compilation I get the following error: error: no matching function for call to ‘Vector::push_back(int&)’ Could someone explain to me why that is? Thank you. #include…
Ryan Smith
  • 11
  • 1
-2
votes
2 answers

push_back of an integer doesn't work on my vector of strings

I am trying to push back 3 vectors in parallel, and when I get to push_back() into the string vector, I get this error: no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=std::string,…
Dami Karv
  • 1
  • 6
-2
votes
1 answer

Why I can't use append() to add a variable to a string?

I have a piece of code: char temp = word[0]; word.erase(0, 1); word.append(temp); //word.push_back(temp); is fine I got an error: error: no matching member function for call to 'append' My question is why I can't use append() here? Thanks in…
yuwanzi
  • 3
  • 2
-2
votes
1 answer

C++ - Vector will only push_back the last digit of number

When I try to use the 'a' option and choose 12, the vector will only add 2: num_vec's elements: 2 9 2 3 4 6 3 9 4 3 2 3 4 2 3 =====Menu===== P - Print Numbers A - Add a number M - Display the mean of numbers S - Display the smallest number L -…
-2
votes
1 answer

push_back getting a vector of last element by self created object

I'm trying to read in a list of Animals, this works fine. Then I want to split each string into two substrings for the name and cmc, this also works fine. But my cout doesn't work. For example, my animal.txt is: Dog|hi cat|miau cow|hihi My…
du7ri
  • 312
  • 2
  • 12
-2
votes
1 answer

Vector won't pushback getline()

So here is the function I'm having push_back problems with: void School::PushBackS(ifstream &in) { string a, b, c, d; while(getline(in, a)) { getline(in, b); getline(in, c); getline(in, d); t.SetStudentID(a); …
tydcghk
  • 1
  • 3
-2
votes
2 answers

c++ list, push_back, & templates?

I am having a very difficult time using push_back on a template object. Can anyone explain why this works list mylist; int myInt; mylist.push_back(myInt); but this won't. list> mylist; int myInt; …
T3nt4c135
  • 104
  • 8