public member function
<deque>
std::deque::resizevoid resize (size_type n, value_type val = value_type());
void resize (size_type n);void resize (size_type n, const value_type& val);
Change size
Resizes the container so that it contains n elements.If n is smaller than the current container size, the content is reduced to its first n elements, removing those beyond (and destroying them).
If n is greater than the current container size, the content is expanded by inserting at the end as many elements as needed to reach a size of n. If val is specified, the new elements are initialized as copies of val, otherwise, they are value-initialized.
Notice that this function changes the actual content of the container by inserting or erasing elements from it.
In case of growth, the storage for the new elements is allocated using the container's allocator, which may throw exceptions on failure (for the default allocator, bad_alloc is thrown if the allocation request does not succeed).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// resizing deque
#include <iostream>
#include <deque>
int main ()
{
std::deque<int> mydeque;
std::deque<int>::iterator it;
// set some initial content:
for (int i=1; i<10; ++i) mydeque.push_back(i);
mydeque.resize(5);
mydeque.resize(8,100);
mydeque.resize(12);
std::cout << "mydeque contains:";
for (std::deque<int>::iterator it = mydeque.begin(); it != mydeque.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
mydeque contains: 1 2 3 4 5 100 100 100 0 0 0 0
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4