std::copy_n
De cppreference.com
![]() | This page has been machine-translated from the English version of the wiki using Google Translate. The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Déclaré dans l'en-tête <algorithm> | ||
template<class InputIt, class Size, class OutputIt > OutputIt copy_n( InputIt first, Size count, OutputIt result ); | ||
Copie exactement
count
valeurs du début de la plage à first
au début de la plage à result
, si count>0
. Ne fait rien autrement .Original:
Copies exactly
count
values from the range beginning at first
to the range beginning at result
, if count>0
. Does nothing otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Sommaire |
[modifier]Paramètres
first | - | le début de la série d'éléments à copier Original: the beginning of the range of elements to copy from The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
count | - | nombre d'éléments à copier Original: number of the elements to copy The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
result | - | le début de la plage de destination Original: the beginning of the destination range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-InputIt must meet the requirements of InputIterator . | ||
-OutputIt must meet the requirements of OutputIterator . |
[modifier]Retourne la valeur
Iterator dans la plage de destination, pointant après le dernier élément copié ou si
count>0
first
autrement .Original:
Iterator in the destination range, pointing past the last element copied if
count>0
or first
otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier]Complexité
Exactement
count
missions, si count>0
.Original:
Exactly
count
assignments, if count>0
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier]Mise en œuvre possible
template<class InputIt, class Size, class OutputIt> OutputIt copy_n(InputIt first, Size count, OutputIt result){if(count >0){*result++=*first;for(Size i =1; i < count;++i){*result++=*++first;}}return result;} |
[modifier]Exemple
#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';}
Résultat :
1234
[modifier]Voir aussi
(C++11) | Copie une série d'éléments vers un nouvel emplacement Original: copies a range of elements to a new location The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction générique) |