Skip to content

example to copy_n #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/standard-library/algorithm-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,35 @@ Returns an output iterator where elements have been copied to. It is the same as

The template function evaluates `*(dest + N) = *(first + N))` once for each `N` in the range `[0, count)`, for strictly increasing values of `N` starting with the lowest value. It then returns `dest + N`. If *dest* and *first* designate regions of storage, *dest* must not be in the range `[first, last)`.

### Example

```cpp
// alg_copy_n.cpp
// compile with: cl /EHsc /W4 alg_copy_n.cpp
#include <algorithm>
#include <iostream>
#include <string>

int main()
{
using namespace std;
string s1{"dandelion"};
string s2{"badger"};

cout << s1 << " + " << s2 << " = ";

// Copy the first 3 letters from s1
// to the first 3 positions in s2
copy_n(s1.begin(), 3, s2.begin());

cout << s2 << endl;
}
```

```Output
dandelion + badger = danger
```

## <a name="count"></a> count

Returns the number of elements in a range whose values match a specified value.
Expand Down