std::vector::assign
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| void assign( size_type count, const T& value ); |
(1) | |
| template< class InputIt > void assign( InputIt first, InputIt last ); |
(2) | |
替换该容器的内容.
1) Original:
Replaces the contents of the container.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
count价值value副本的内容替换Original:
replaces the contents with
count copies of value valueThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
的内容替换的范围内
[first, last)的副本Original:
replaces the contents with copies of those in the range
[first, last)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| count | - | 容器的新的大小
Original: the new size of the container The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| value | - | 的值初始化容器的元素
Original: the value to initialize elements of the container with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| first, last | - | 取值范围为从复制元素
Original: the range to copy the elements from The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
| Type requirements | ||
-InputIt must meet the requirements of InputIterator.
| ||
[编辑] 复杂性
1)线性
2) countOriginal:
linear in
countThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
first和last之间的距离呈线性关系Original:
linear in distance between
first and lastThe text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
下面的代码使用
assign添加一个std::vector<char>几个字符
Original:
The following code uses
assign to add several characters to a std::vector<char>:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
#include <vector> #include <iostream> int main() { std::vector<char> characters; characters.assign(5, 'a'); for (char c : characters) { std::cout << c << '\n'; } return 0; }
Output:
a a a a a
[编辑] 另请参阅
| 构建 vector Original: constructs the vector The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |