Results 1 to 5 of 5

Thread: How to use the pop_back() in C++

  1. #1
    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!!!!

  2. #2
    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.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    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.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    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

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,064,960.15621 seconds with 15 queries