stl中copy()函数_std :: copy()函数以及C ++ STL中的示例
stl中copy()函數(shù)
C ++ STL std :: copy()函數(shù) (C++ STL std::copy() function)
copy() function is a library function of algorithm header, it is used to copy the elements of a container, it copies the elements of a container from given range to another container from a given beginning position.
copy()函數(shù)是算法標(biāo)頭的庫(kù)函數(shù),用于復(fù)制容器的元素,它將容器的元素從給定范圍復(fù)制到給定起始位置的另一個(gè)容器。
Note:To use copy() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.
注意:要使用copy()函數(shù) –包括<algorithm>頭文件,或者您可以簡(jiǎn)單地使用<bits / stdc ++。h>頭文件。
Syntax of std::copy() function
std :: copy()函數(shù)的語(yǔ)法
std::copy(iterator source_first, iterator source_end, iterator target_start);Parameter(s):
參數(shù):
iterator source_first, iterator source_end – are the iterator positions of the source container.
迭代器source_first,迭代器source_end –是源容器的迭代器位置。
iterator target_start – is the beginning iterator of the target container.
迭代器target_start –是目標(biāo)容器的開(kāi)始迭代器。
Return value: iterator – it is an iterator to the end of the target range where elements have been copied.
返回值: 迭代器 –它是目標(biāo)元素已復(fù)制到目標(biāo)范圍末尾的迭代器。
Example:
例:
Input://declaring & initializing an int arrayint arr[] = { 10, 20, 30, 40, 50 };//vector declarationvector<int> v1(5);//copying array elements to the vectorcopy(arr, arr + 5, v1.begin());Output://if we print the valuearr: 10 20 30 40 50v1: 10 20 30 40 50C ++ STL程序演示了std :: copy()函數(shù)的使用 (C++ STL program to demonstrate use of std::copy() function)
In this example, we are copying the array elements to the vector.
在此示例中,我們將數(shù)組元素復(fù)制到向量。
//C++ STL program to demonstrate use of //std::copy() function #include <iostream> #include <algorithm> #include <vector> using namespace std;int main() {//declaring & initializing an int arrayint arr[] = { 10, 20, 30, 40, 50 };//vector declarationvector<int> v1(5);//copying array elements to the vectorcopy(arr, arr + 5, v1.begin());//printing arraycout << "arr: ";for (int x : arr)cout << x << " ";cout << endl;//printing vectorcout << "v1: ";for (int x : v1)cout << x << " ";cout << endl;return 0; }Output
輸出量
arr: 10 20 30 40 50 v1: 10 20 30 40 50Reference: C++ std::copy()
參考: C ++ std :: copy()
翻譯自: https://www.includehelp.com/stl/std-copy-function-with-example.aspx
stl中copy()函數(shù)
總結(jié)
以上是生活随笔為你收集整理的stl中copy()函数_std :: copy()函数以及C ++ STL中的示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java字符串最长回文串_Java中的字
- 下一篇: 茱莉亚分形_茱莉亚的NaN Consta