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

Sponsored Links



Use of the insert() in C++

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 12-03-2010
Member
 
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.

Reply With Quote
  #2  
Old 12-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,946
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);
Reply With Quote
  #3  
Old 12-03-2010
Member
 
Join Date: May 2008
Posts: 2,004
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
Reply With Quote
  #4  
Old 12-03-2010
Member
 
Join Date: Apr 2008
Posts: 1,997
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.
Reply With Quote
  #5  
Old 12-03-2010
Member
 
Join Date: May 2008
Posts: 2,286
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,
Reply With Quote
  #6  
Old 12-03-2010
Member
 
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
Reply With Quote
Reply

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



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Use of the insert() in C++"
Thread Thread Starter Forum Replies Last Post
How to insert PCI-E x16 in PCI-E x4 slot? Kalatapaswi Monitor & Video Cards 5 03-07-2011 09:00 PM
Can I insert SSD into Eee PC? OPinaArTy Portable Devices 5 08-02-2011 02:20 PM
How to insert value into tuple? MKAIF Software Development 5 22-02-2010 06:20 PM
wmv, pps insert into a web page filldirt Windows Software 6 19-06-2009 09:15 PM
Please Insert the Correct CD/DVD JAMIN Hardware Peripherals 3 17-03-2009 03:30 PM


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