日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

stl中copy()函数_std :: rotate_copy()函数以及C ++ STL中的示例

發(fā)布時(shí)間:2023/12/1 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stl中copy()函数_std :: rotate_copy()函数以及C ++ STL中的示例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

stl中copy()函數(shù)

C ++ STL std :: rotate_copy()函數(shù) (C++ STL std::rotate_copy() function)

rotate_copy() function is a library function of algorithm header, it is used to rotate left the elements of a sequence within a given range and copy the rotating elements to another sequence, it accepts the range (start, end) of the input sequence, a middle point, and an iterator pointing to start element of result sequence. It rotates the elements in such a way that the element pointed by the middle iterator becomes the new first element.

rotation_copy()函數(shù)是算法標(biāo)頭的庫(kù)函數(shù),用于在給定范圍內(nèi)向左旋轉(zhuǎn)序列的元素,并將旋轉(zhuǎn)的元素復(fù)制到另一個(gè)序列,它接受輸入序列的范圍(開(kāi)始,結(jié)束),一個(gè)中間點(diǎn),以及一個(gè)指向結(jié)果序列開(kāi)始元素的迭代器。 它以使中間迭代器指向的元素成為新的第一個(gè)元素的方式旋轉(zhuǎn)元素。

Note: To use rotate_copy() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.

注意:要使用rotate_copy()函數(shù) –包括<algorithm>頭文件,或者您可以簡(jiǎn)單地使用<bits / stdc ++。h>頭文件。

Syntax of std::rotate_copy() function

std :: rotate_copy()函數(shù)的語(yǔ)法

std::rotate_copy(iterator start, iterator middle, iterator end, iterator start_result);

Parameter(s):

參數(shù):

  • iterator start – an iterator pointing to the first element of the sequence.

    迭代器開(kāi)始 –指向序列第一個(gè)元素的迭代器。

  • iterator middle – an iterator pointing to the middle or any other elements from where we want to start the rotation.

    中間迭代器 –指向中間或我們要開(kāi)始旋轉(zhuǎn)的位置的任何其他元素的迭代器。

  • iterator end – an iterator pointing to the last element of the sequence.

    迭代器末端 –指向序列的最后一個(gè)元素的迭代器。

  • iterator start_result – an iterator pointing to the first element in result sequence.

    iterator start_result –指向結(jié)果序列中第一個(gè)元素的迭代器。

Return value: void – it returns noting.

返回值: void –返回注釋。

Example:

例:

Input://an array (source)int arr[] = { 10, 20, 30, 40, 50 };//vectorvector<int> v(5);//rotating and copy array elements to the vectorrotate_copy(arr + 0, arr + 2, arr + 5, v.begin());Output:vector elements: 30 40 50 10 20

C ++ STL程序演示了std :: rotate_copy()函數(shù)的使用 (C++ STL program to demonstrate use of std::rotate_copy() function)

In this program, we have an array and a vector; we are rotating its elements from 2nd index and copying into the vector.

在這個(gè)程序中,我們有一個(gè)數(shù)組和一個(gè)向量。 我們將其元素從第二索引旋轉(zhuǎn)并復(fù)制到向量中。

//C++ STL program to demonstrate use of //std::rotate_copy() function #include <iostream> #include <algorithm> #include <vector> using namespace std;//main code int main() {//an array (source)int arr[] = { 10, 20, 30, 40, 50 };//vectorvector<int> v(5);//printing array and vector elementscout << "array elements..." << endl;for (int x : arr)cout << x << " ";cout << endl;cout << "vector elements begfore rotating..." << endl;for (int x : v)cout << x << " ";cout << endl;//rotating and copy array elements to the vectorrotate_copy(arr + 0, arr + 2, arr + 5, v.begin());cout << "vector elements after rotating..." << endl;for (int x : v)cout << x << " ";cout << endl;return 0; }

Output

輸出量

array elements... 10 20 30 40 50 vector elements begfore rotating... 0 0 0 0 0 vector elements after rotating... 30 40 50 10 20

Reference: C++ std::rotate_copy()

參考: C ++ std :: rotate_copy()

翻譯自: https://www.includehelp.com/stl/std-rotate_copy-function-with-example.aspx

stl中copy()函數(shù)

總結(jié)

以上是生活随笔為你收集整理的stl中copy()函数_std :: rotate_copy()函数以及C ++ STL中的示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。