[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/container/vector/assign [Back]  [Original]

std::vector::assign cppreference.com
cppreference.com

std::vector::assign

cppreference.com

<metanoindex/>

<tbody> </tbody>
void assign( size_type count, const T& value );
(1)
template< class InputIt > void assign( InputIt first, InputIt last );
(2)
.
:
Replaces the contents of the container.
Google.
. .

1)

count value
:
replaces the contents with count copies of value value
Google.
. .

2)

, [first, last)
:
replaces the contents with copies of those in the range [first, last)
Google.
. .

count
:
the new size of the container
Google.
. .
value
:
the value to initialize elements of the container with
Google.
. .
first, last
:
the range to copy the elements from
Google.
. .
-
InputIt InputIterator.

1)

count
:
linear in count
Google.
. .

2)

first last
:
linear in distance between first and last
Google.
. .

assign std::vector<char>
:
The following code uses assign to add several characters to a std::vector<char>:
Google.
. .

#include <vector>
#include <iostream>

int main()
{
    std::vector<char> characters;

    characters.assign(5, 'a');

    for (char c : characters) {
        std::cout << c << '\n';
    }

    return 0;
}

:

a
a
a
a
a

.

vector
(public -) []

Web Proxy Viewer  |  New URL  |  Original Page