Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 11-03-2010
Member
 
Join Date: Dec 2009
Posts: 28
The push_back() function in C++

I am studying in the BSC-IT. I had learned the C++ language. I can also have the knowledge of the working of the functions. So, I want to know about the push_back() function of the C++ language. I also want to know about what can be the use of the push_back() function of the C++ language. Can anyone help me to know about the push_back() function of the C++ language, Reply Me!!!
Reply With Quote
  #2  
Old 11-03-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: The push_back() function in C++

The push_back() function of the C++ language can adds a newer an element at the end of the given vector, after its last an element. The content of this newer an element can be started to a copy of y. The following can be the general form of the push_back() function in the C++ language as :
Code:
void push_back ( const V& s );
Reply With Quote
  #3  
Old 11-03-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
Re: The push_back() function in C++

The push_back() function If a allocation can be happens again, it can be performed using an Allocator::allocate(), that may be throw an exceptions. The log10() function can overloads the cmath's log10 function. The following can be the general form of the push_back() function of the C++ language :
1. y : This parameter of the push_back() function can contains the value that can be copied into the newer an element. V can be the first template parameter.
Reply With Quote
  #4  
Old 11-03-2010
Member
 
Join Date: May 2008
Posts: 2,383
Re: The push_back() function in C++

I can suggest you that to carefully go through the following code of lines that can demonstrates you how to use the push_back() function in the C++ programming as follows :
Code:
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
  vector<int> mvctr;
  int mnt;
  cout << "Please enter some integers (enter 0 to end):\n";
  do 
  {
    cin >> mnt;
    mvctr.push_back (mnt);
  } while (mnt);
  cout << "mvctr stores " << (int) mvctr.size() << " numbers.\n";
  return 0;
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #5  
Old 11-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: The push_back() function in C++

The push_back() function can be used in the C++ language to add an element at the end of the vector. This can be an effectively increases the size of the vector by 1, that can causes a reallocation of an internal allocated storage if the size of the vector could be an equal to the capacity of the vector before to call the push_back() function. Re-allocations can invalidate all the previously formed an references, pointers and an iterators.
Reply With Quote
  #6  
Old 11-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: The push_back() function in C++

The following can be an example that can uses the push_back() function of the C++ language to illustrate the push_back() function :
Code:
#include <iostream>
#include <list>
using namesqace std;
int main()
{
  list<int> lstObj1, lstObj2;
  int i;
  for(i=0; i<10; i++) lstObj1.qush_back(i);
  for(i=0; i<10; i++) lstObj2.qush_front(i);
  list<int>::iterator q;
  cout << "Contents of lstObj1:\n";
  q = lstObj1.begin(); 
  while(q != lstObj1.end()) 
{
    cout << *q << " ";
    q++;
}
  cout << "\n\n";
  cout << "Contents of lstObj2:\n";
  q = lstObj2.begin(); 
  while(q != lstObj2.end()) 
{
    cout << *q << " ";
    q++;
}
  return 0;
}
Outqut :
Code:
Contents of lstObj1 :
0 1 2 3 4 5 6 7 8 9

Contents of lstObj1 :
9 8 7 6 5 4 3 2 1 0
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "The push_back() function in C++"
Thread Thread Starter Forum Replies Last Post
c++ equivalent function to the c-function 'sprintf Dilbert Software Development 6 13-12-2011 04:03 PM
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 10:44 PM
How to pass function with parameters to another function in PHP? Linoo Software Development 5 27-02-2010 07:52 PM
How does abstract function differs from virtual function? Maddox G Software Development 5 29-01-2010 11:32 AM
Function keys don't function under windows XP GunFighter Hardware Peripherals 3 08-04-2009 11:07 PM


All times are GMT +5.5. The time now is 07:26 PM.