共用方式為


deque::assign

清除雙向佇列中的元素,並複製新元素組至目標雙向佇列 。

template<class InputIterator>
    void assign(
    InputIterator First,
    InputIterator Last);
void assign(
    size_type Count,
    const Type& Val
);
void assign(
    initializer_list<Type> IList
);

參數

  • First
    在要從引數雙向佇列中複製之項目範圍中第一個項目的位置。

  • Last
    在要從引數雙向佇列中複製之項目範圍外第一個項目的位置。

  • Count
    插入於雙向佇列中項目的複本數目。

  • Val
    插入於雙向佇列中之項目的值。

  • IList
    插入於雙向佇列的 initializer_list。

備註

在清除目標雙向佇列中所有現存的項目之後,assign 要不是從原始的雙向佇列或從其他雙向佇列,插入指定範圍中的項目到目標雙向佇列,就會插入一個指定值的新增項目副本到目標雙向佇列。

範例

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

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);

    deque<int> d1{ 1, 2, 3, 4 };
    initializer_list<int> iList{ 5, 6, 7, 8 };
    d1.assign(iList);

    cout << "d1 = ";
    for (int i : d1)
        cout << i;
    cout << endl;

    cout << "c1 =";
    for (int i : c1)
        cout << i;
    cout << endl;

    c1.assign(++c2.begin(), c2.end());
    cout << "c1 =";
    for (int i : c1)
        cout << i;
    cout << endl;

    c1.assign(7, 4);
    cout << "c1 =";
    for (int i : c1)
        cout << i;
    cout << endl;

}
  

需求

標頭: <deque>

命名空間: std

請參閱

參考

deque 類別

deque::assign 和 deque::swap

標準樣板程式庫