|
| ||||||||||
| Tags: cpp, functions, header files, insert, vector |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Use of the insert() in C++
|
|
#2
| ||||
| ||||
| 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
| |||
| |||
| 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;
} Code: mvctr contains: 501 502 503 300 300 400 400 200 100 100 100 |
|
#4
| ||||
| ||||
| 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
| ||||
| ||||
| 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 :
|
|
#6
| ||||
| ||||
| 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;
} Code: Before, w2 ks: 5 6 7 8
After, w2 ks: 5 6 7 8 0 1 2 3 |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |