English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C++ Deque (Double-ended Queue)
C ++ The Deque Assign() function assigns new content to the deque container and modifies the size of the container accordingly.
void assign(InputIterator first, InputIterator last); void assign(int n, value_type val);
(first, last): It defines the range of new elements to be inserted.
n: It defines the new size of the deque container.
val: The new value to be inserted.
It does not return any value.
Let's look at a simple example
#include <iostream> #include<deque> using namespace std; int main() { deque<int> first = {1,2,3,4}; deque<int> second; deque<int>::iterator itr = second.begin(); second.assign(first.begin(), first.end()); for(itr = second.begin(); itr != second.end();++itr) std::cout <<*itr << " "; return 0; }
Output:
1 2 3 4
In this example, assign() assigns the content of the first container to the second container.
Let's look at a simple example
#include <iostream> #include<deque> using namespace std; int main() { deque<int> deq; deque<int>::iterator itr; deq.assign(5,6); for(itr=deq.begin();itr!=deq.end();++itr) std::cout << *itr << " "; return 0; }
Output:
6 6 6 6 6
In this example, the assign() function will be called five times 6The value is assigned to the deq container.