次の方法で共有


multiset::insert

Inserts an element or a range of elements into a multiset.

iterator insert(
   const value_type& _Val
);
iterator insert(
   iterator _Where,
   const value_type& _Val
);
template<class InputIterator>
   void insert(
      InputIterator _First,
      InputIterator _Last
   );

Parameters

  • _Val
    The value of an element to be inserted into the multiset unless the multiset already contains that element or, more generally, an element whose key is equivalently ordered.

  • _Where
    The place to start searching for the correct point of insertion. Insertion can occur in amortized constant time instead of logarithmic time, if the insertion point immediately follows _Where.

  • _First
    The position of the first element to be copied from a multiset.

  • _Last
    The position just beyond the last element to be copied from a multiset.

Return Value

The insert member functions returns an iterator that points to the position where the new element was inserted into the multiset.

Remarks

The third member function inserts the sequence of element values into a multiset corresponding to each element addressed by an iterator in the range [_First, _Last) of a specified multiset.

Example

// multiset_insert.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   multiset <int>::iterator ms1_pIter, ms2_pIter;

   multiset <int, less<int> > ms1, ms2;
   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );
   ms1.insert( 40 );

   cout << "The original ms1 =";
   for ( ms1_pIter = ms1.begin( ); ms1_pIter != ms1.end( ); ms1_pIter++ )
      cout << " " << *ms1_pIter;
   cout << "." << endl;

   ms1.insert( 20 );
   ms1.insert( --ms1.end( ), 50 );

   cout << "After the insertions, ms1 =";
   for ( ms1_pIter = ms1.begin( ); ms1_pIter != ms1.end( ); ms1_pIter++ )
      cout << " " << *ms1_pIter;
   cout << "." << endl;

   ms2.insert( 100 );
   ms2.insert( ++ms1.begin( ), --ms1.end( ) );

   cout << "ms2 =";
   for ( ms2_pIter = ms2.begin( ); ms2_pIter != ms2.end( ); ms2_pIter++ )
      cout << " " << *ms2_pIter;
   cout << "." << endl;
}

The original ms1 = 10 20 30 40.
After the insertions, ms1 = 10 20 20 30 40 50.
ms2 = 20 20 30 40 100.

Requirements

Header: <set>

Namespace: std

See Also

Concepts

multiset Class

multiset Members

Standard Template Library