std::copy_n
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'header <algorithm>
|
||
template< class InputIt, class Size, class OutputIt > OutputIt copy_n( InputIt first, Size count, OutputIt result ); |
||
Copies exactly count
values from the range beginning at first
to the range beginning at result
, if count>0
. Does nothing otherwise.
Indice |
[modifica] Parametri
first | - | the beginning of the range of elements to copy from |
count | - | number of the elements to copy |
result | - | l'inizio del campo di destinazione
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 .
|
[modifica] Valore di ritorno
Iterator in the destination range, pointing past the last element copied if count>0
or first
otherwise.
[modifica] Complessità
Exactly count
assignments, if count>0
.
[modifica] Possibile implementazione
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; } |
[modifica] Esempio
#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'; }
Output:
1234
[modifica] Vedi anche
(C++11) |
copia un intervallo di elementi in una nuova posizione 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. (funzione di modello) |