Results 1 to 6 of 6

Thread: Use of the insert() in C++

  1. #1
    Join Date
    Dec 2009
    Posts
    31

    Use of the insert() in C++

    I an interested in doing the C++ language programming. I had learned the C++ language in the BSC-IT. I can know the actual concept or working of the C++ functions. So, I want to know what is the insert() function of the C++ language. I also want to know what is the use of the insert() function in the C++ programming. Can anyone knows about the insert() function of C++ language.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,949

    Re: Use of the insert() in C++

    The insert() function of the C++ language can be used to insert an elements of the given specified vector. The vector can be an extended by inserting newer an elements before an element that can be at position. The following can be the general syntax of the insert() function of the C++ language :
    Code:
    iterator insert ( iterator pstn, const S& y);
        void insert ( iterator pstn, size_type m, const S& y);
    template <class InptItrtr>
        void insert ( iterator position, InptItrtr fst, InptItrtr lst);

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

    Re: Use of the insert() in C++

    I can suggest you that to carefully go through the following code of lines that can demonstrates you how to use the insert() function in the C++ programming as follows :
    Code:
    #include <iostream>
    #include <vector>
    using namespace std;
    int main ()
    {
      vector<int> mvctr (3,100);
      vector<int>::iterator a;
      a = mvctr.begin();
      a = mvctr.insert ( a , 200 );
      mvctr.insert (a,2,300);
      a = mvctr.begin();
      vector<int> anthrvctr (2,400);
      mvctr.insert (a+2,anthrvctr.begin(),anthrvctr.end());
      int mry [] = { 501,502,503 };
      mvctr.insert (mvctr.begin(), mry, mry+3);
      cout << "mvctr contains:";
      for (a=mvctr.begin(); a<mvctr.end(); a++)
      cout << " " << *a;
      cout << endl;
      return 0;
    }
    Output:
    Code:
    mvctr contains: 501 502 503 300 300 400 400 200 100 100 100

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

    Re: Use of the insert() in C++

    The following can be the general syntax of the insert() function in the C++ language :
    1. m : This parameters of the insert() function can contains a number of an elements that can be used to insert. Every an element can be initialized to the value that can be specified in y.
    2. y : This parameters of the insert() function can contains a value that can be used to start the inserted an elements.
    3. pstn : This parameters of the insert() function can contains a position in the given specified vector.
    4. fst, lst : These parameters of the insert() function that can contains an iterators specifying a given range of an elements.

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

    Re: Use of the insert() in C++

    The insert() function of the C++ language can be used to insert an element into the given specified vector. The insert method can be either the following :
    1. inserts num copies of val before loc, or
    2. inserts the elements from start to end before loc.
    3. inserts val before loc, returning an iterator to the element inserted,

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Use of the insert() in C++

    Here can be the one more example on the insert() function of the C++ language and the following program can help's you to learn the insert() function :
    Code:
    #include <map>
    #include <iostream>
    int main( )
    {
        vector<knt> w1;
        w1.push_back( 0 );
        w1.push_back( 1 );
        w1.push_back( 2 );
        w1.push_back( 3 );
        vector<knt> w2;
        w2.push_back( 5 );
        w2.push_back( 6 );
        w2.push_back( 7 );
        w2.push_back( 8 );
        cout << "Before, w2 ks: ";
        for( vector<knt>::skze_type k = 0; k < w2.skze(); k++ ) 
    {
          cout << w2[k] << " ";
        }
        cout << endl;
        w2.knsert( w2.end(), w1.begkn(), w1.end() );
        cout << "After, w2 ks: ";
        for( vector<knt>::skze_type k = 0; k < w2.skze(); k++ ) 
    {
          cout << w2[k] << " ";
        }
        cout << endl;
    }
    OUTPUT :
    Code:
        Before, w2 ks: 5 6 7 8
        After, w2 ks: 5 6 7 8 0 1 2 3

Similar Threads

  1. How to insert PCI-E x16 in PCI-E x4 slot?
    By Kalatapaswi in forum Monitor & Video Cards
    Replies: 5
    Last Post: 03-07-2011, 09:00 PM
  2. Can I insert SSD into Eee PC?
    By OPinaArTy in forum Portable Devices
    Replies: 5
    Last Post: 08-02-2011, 02:20 PM
  3. How to insert value into tuple?
    By MKAIF in forum Software Development
    Replies: 5
    Last Post: 22-02-2010, 06:20 PM
  4. wmv, pps insert into a web page
    By filldirt in forum Windows Software
    Replies: 6
    Last Post: 19-06-2009, 09:15 PM
  5. Please Insert the Correct CD/DVD
    By JAMIN in forum Hardware Peripherals
    Replies: 3
    Last Post: 17-03-2009, 03:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •