Results 1 to 6 of 6

Thread: The push_back() function in C++

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

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    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 );

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    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.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    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;
    }

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    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.

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

Similar Threads

  1. c++ equivalent function to the c-function 'sprintf
    By Dilbert in forum Software Development
    Replies: 6
    Last Post: 13-12-2011, 04:03 PM
  2. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  3. Replies: 5
    Last Post: 27-02-2010, 07:52 PM
  4. How does abstract function differs from virtual function?
    By Maddox G in forum Software Development
    Replies: 5
    Last Post: 29-01-2010, 11:32 AM
  5. Function keys don't function under windows XP
    By GunFighter in forum Hardware Peripherals
    Replies: 3
    Last Post: 08-04-2009, 11:07 PM

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,726,861,967.48337 seconds with 17 queries