resize
语法:
1 |
void resize( size_type num, TYPE val ); |
resize()函数把list的大小改变到num。被加入的多余的元素都被赋值为val
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
源代码 /** * @brief Resizes the %list to the specified number of elements. * @param new_size Number of elements the %list should contain. * @param x Data with which new elements should be populated. * * This function will %resize the %list to the specified number * of elements. If the number is smaller than the %list's * current size the %list is truncated, otherwise the %list is * extended and new elements are populated with given data. */ void resize(size_type __new_size, const value_type& __x); /** * @brief Resizes the %list to the specified number of elements. * @param new_size Number of elements the %list should contain. * * This function will resize the %list to the specified number of * elements. If the number is smaller than the %list's current * size the %list is truncated, otherwise the %list is extended * and new elements are default-constructed. */ void resize(size_type __new_size) { this->resize(__new_size, value_type()); } |
测试代码
测试结果
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7 5 5 5 5 5 5 5 5 5 5 5 5