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: 26
How to use the pop_back() in C++

I am working in the XYZ company as software developer. We can use the C++ language for developing the software. Hence, I can not know about the pop_back() function of the C++ language. So, I would like to know about the pop_back() function of the C++ language. I also would like to know about how to the use of the pop_back() function of the C++ language. Can anyone has the solution for me then reply!!!!
Reply With Quote
  #2  
Old 11-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: How to use the pop_back() in C++

The pop_back() function of the C++ language can be used to delete the last of an element. The pop_back() function can removes the last an element in the given specified vector by an effectively decreasing the size of the vector by 1 and invalidating all of an iterators and references to it. This calls the removed an element's destructor.
Reply With Quote
  #3  
Old 11-03-2010
Member
 
Join Date: May 2008
Posts: 2,008
Re: How to use the pop_back() in C++

The pop_back() function of the C++ can removes an element that can be at the end of the given specified vector. The pop_back() function can be comes under the vector containers. This pop_push() function can be called by the deleted an element's destructor. The following can be the general form of the log10() function of the C++ language :
Code:
void pop_back( );

Last edited by Katty : 11-03-2010 at 04:06 PM.
Reply With Quote
  #4  
Old 11-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: How to use the pop_back() in C++

The following can be an example that can uses the pop_back() function of the C++ language to illustrate the pop_back() function :
Code:
#include <vector>
#include <iostream>
int main( )
{
   using namespace std;   
   vector <int> w1;
   w1.push_back( 1 );
   cout << w1.back( ) << endl;
   w1.push_back( 2 );
   cout << w1.back( ) << endl;
   w1.pop_back( );
   cout << w1.back( ) << endl;
}
Output
Code:
1
2
1
Reply With Quote
  #5  
Old 11-03-2010
Member
 
Join Date: May 2008
Posts: 2,293
Re: How to use the pop_back() in C++

The pop_back() function or method can deletes the last an element of the given specified vector. The pop_back() function can be executed in constant time. In the following an example, the elements can be popped out of the given specified vector after they can be added up in the summation function as follows :
Code:
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
  vector<int> mvctr;
  int summation (0);
  mvctr.push_back (100);
  mvctr.push_back (200);
  mvctr.push_back (300);
  while (!mvctr.empty())
  {
    summation+=mvctr.back();
    mvctr.pop_back();
  }
  cout << "The elements of mvctr summed " << summation << endl;
  return 0;
}
Output:
Code:
The elements of mvctr summed 600
Reply With Quote
Reply

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search



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