次の方法で共有


deque::assign

Erases elements from a deque and copies a new set of elements to the target deque.

template<class InputIterator>
   void assign(
      InputIterator _First,
      InputIterator _Last
   );
void assign(
   size_type _Count,
   const Type& _Val
);

Parameters

  • _First
    Position of the first element in the range of elements to be copied from the argument deque.

  • _Last
    Position of the first element beyond the range of elements to be copied from the argument deque.

  • _Count
    The number of copies of an element being inserted into the deque.

  • _Val
    The value of the element being inserted into the deque.

Remarks

After erasing any existing elements in the target deque, assign either inserts a specified range of elements from the original deque or from some other deque into the target deque or inserts copies of a new element of a specified value into the target deque.

Example

// deque_assign.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>

int main( ) 
{
   using namespace std;
   deque <int> c1, c2;
   deque <int>::const_iterator cIter;
   
   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );
   c2.push_back( 40 );
   c2.push_back( 50 );
   c2.push_back( 60 );

   cout << "c1 =";
   for ( cIter = c1.begin( ); cIter != c1.end( ); cIter++ )
      cout << " " << *cIter;
   cout << endl;

   c1.assign( ++c2.begin( ), c2.end( ) );
   cout << "c1 =";
   for ( cIter = c1.begin( ); cIter != c1.end( ); cIter++ )
      cout << " " << *cIter;
   cout << endl;

   c1.assign( 7, 4 );
   cout << "c1 =";
   for ( cIter = c1.begin( ); cIter != c1.end( ); cIter++ )
      cout << " " << *cIter;
   cout << endl;
}
c1 = 10 20 30
c1 = 50 60
c1 = 4 4 4 4 4 4 4

Requirements

Header: <deque>

Namespace: std

See Also

Reference

deque Class

deque::assign and deque::swap

Standard Template Library

Other Resources

deque Class Members