std::forward_list::resize
void resize( size_type count ); | (1) | |
|---|---|---|
void resize( size_type count, const value_type& value ); | (2) | |
调整容器的大小以包含count元素。
如果当前大小大于count,容器被简化为第一个容器。count元素。
如果当前大小小于count,,,
1%29默认插入元素追加
2%29份value附加
参数
count | - | new size of the container |
|---|---|---|
value | - | the value to initialize the new elements with |
类型要求
T必须符合DefaultInsertable的要求,才能使用过载%281%29。
T必须满足CopyInsertable的要求才能使用过载%282%29。
返回值
%280%29
复杂性
当前大小与count...
例
二次
#include <iostream>
#include <forward_list>
int main()
{
std::forward_list<int> c = {1, 2, 3};
std::cout << "The forward_list holds: ";
for(auto& el: c) std::cout << el << ' ';
std::cout << '\n';
c.resize(5);
std::cout << "After resize up 5: ";
for(auto& el: c) std::cout << el << ' ';
std::cout << '\n';
c.resize(2);
std::cout << "After resize down to 2: ";
for(auto& el: c) std::cout << el << ' ';
std::cout << '\n';
}二次
产出:
二次
The forward_list holds: 1 2 3
After resize up 5: 1 2 3 0 0
After resize down to 2: 1 2二次
另见
insert_after | inserts elements after an element (public member function) |
|---|---|
erase_after | erases an element after an element (public member function) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

