Or login with:
#include <algorithm> template < class InputIterator, class Size, class OutputIterator > OutputIterator copy_n( InputIterator first, Size count, OutputIterator result );Parameters:
| Parameter | Description |
|---|---|
| first | An input iterator that indicates where to copy elements from |
| count | A signed or unsigned integer type specifying the number of elements to copy |
| result | An output iterator that indicates where to copy elements to |
[first, first + n) to the range [result, result + n).result.#include <iostream> #include <string> #include <algorithm> #include <iterator> int main() { std::string in = "1234567890"; std::string out; std::copy_n(in.begin(), 4, std::back_inserter(out)); std::cout <<out <<'\n'; return 0; }
You must login to leave a messge