Skip to content

Commit 4e593c1

Browse files
author
Colin Robertson
authored
Merge pull request MicrosoftDocs#1104 from EmilEnchev/patch-6
example to copy_n
2 parents 4608eca + c9701fc commit 4e593c1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/standard-library/algorithm-functions.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,35 @@ Returns an output iterator where elements have been copied to. It is the same as
658658

659659
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)`.
660660

661+
### Example
662+
663+
```cpp
664+
// alg_copy_n.cpp
665+
// compile with: cl /EHsc /W4 alg_copy_n.cpp
666+
#include <algorithm>
667+
#include <iostream>
668+
#include <string>
669+
670+
int main()
671+
{
672+
using namespace std;
673+
string s1{"dandelion"};
674+
string s2{"badger"};
675+
676+
cout << s1 << " + " << s2 << " = ";
677+
678+
// Copy the first 3 letters from s1
679+
// to the first 3 positions in s2
680+
copy_n(s1.begin(), 3, s2.begin());
681+
682+
cout << s2 << endl;
683+
}
684+
```
685+
686+
```Output
687+
dandelion + badger = danger
688+
```
689+
661690
## <a name="count"></a> count
662691

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

0 commit comments

Comments
 (0)