[c++] std::copy 2차원 배열 복사

모험가·2022년 6월 11일
0

c++

목록 보기
4/4
post-thumbnail

std::copy

SYNOPSIS

template <class InputIterator, class OutputIterator>
  OutputIterator copy (InputIterator first, InputIterator last, OutputIterator result);

LIBRARY
#include <>

DESCRIPTION
Copy range of elements
Copies the elements in the range [first,last) into the range beginning at result.
The function returns an iterator to the end of the destination range (which points to the element following the last element copied).

정해진 크기의 요소들을 복사한다.

Parameters
first : 시작 주소
end : 끝 주소
result : 복사할 공간의 시작주소

example
copy(시작 지점, 끝나는 지점, 복사 될 시작지점)


array[10]을 array_copy[10]에 복사하고자한다면

copy(array, array+10, array_copy);

2차원 배열의 경우
array[10][10]을 array_copy[10][10]에 복사한다고 할 때
copy(&array[0][0], &array[0][0]+100, &array_copy[0][0]);

+ 벡터의 경우
  copy(v.begin(), v.end(), v_copy.begin());
profile
부산 싸나이의 모험기

0개의 댓글