std::fill
Материал из 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. |
Заголовочный файл <algorithm>
|
||
template< class ForwardIt, class T > void fill( ForwardIt first, ForwardIt last, const T& value ); |
||
Назначение данного
value
к элементам в диапазоне [first, last)
.Original:
Assigns the given
value
to the elements 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.
Содержание |
[править] Параметры
first, last | - | диапазон элементов изменить
Original: the range of elements to modify 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 be assigned The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-ForwardIt must meet the requirements of ForwardIterator .
|
[править] Возвращаемое значение
(Нет)
Original:
(none)
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.
[править] Сложность
Именно
last - first
заданий.Original:
Exactly
last - first
assignments.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.
[править] Возможная реализация
template< class ForwardIt, class T > void fill(ForwardIt first, ForwardIt last, const T& value) { for (; first != last; ++first) { *first = value; } } |
[править] Пример
Следующий код использует
fill()
, чтобы установить все элементы вектора целых чисел до -1
Original:
The following code uses
fill()
to set all of the elements of a vector of integers to -1:
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 <algorithm> #include <vector> #include <iostream> int main() { int data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } std::vector<int> v1(data, data+10); std::fill(v1.begin(), v1.end(), -1); for (vector<int>::iterator it = v1.begin(); it != v1.end(); ++it) { std::cout << *it << " "; } std::cout << "\n"; }
Вывод:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1
[править] См. также
присваивает значение числа элементов Original: assigns a value to a number of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
сохраняет результат функции в диапазоне Original: saves the result of a function in a range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) | |
применяет функцию к различным элементам Original: applies a function to a range of elements The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон функции) |