此函数位于头文件:
#include <algorithm>
原型为:
output_iterator copy( input_iterator start, input_iterator end, output_iterator dest );The copy function copies the elements between start and end to dest. In other words, after copy has run,
*dest = *start
*(dest+1) = *(start+1)
*(dest+2) = *(start+2)
...
*(dest+N) = *(start+N)
主要功能就是完成拷贝
For example, the following code uses copy to both copy the contents of one vector to another and to display the resulting vector:
vector<int> from_vector;
for( int i = 0; i < 10; i++ ) {
from_vector.push_back( i );
}
vector<int> to_vector(10);
copy( from_vector.begin(), from_vector.end(), to_vector.begin() );
cout << "to_vector contains: ";
copy( to_vector.begin(), to_vector.end(), ostream_iterator<int>( cout, " " ) );
cout << endl;