Next: Kopieren (forts.)
Up: Algorithmen
Previous: Sortieren
copy()
back_inserter(container),
front_inserter(container) und
inserter(container,pos)
erweitern den Zielbereich automatisch.
Beispiel ohne Insert-Iterator
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
typedef vector<int> VectorOfInts;
VectorOfInts tip1, tip2;
tip1.push_back(45);
tip1.push_back(1);
tip1.push_back(17);
tip1.push_back(27);
tip2.resize(tip1.size()); // Vorher genügend Platz
// für die neuen Elemente schaffen.
copy( tip1.begin(), // Quelle start
tip1.end(), // Quelle ende
tip2.begin()); // Ziel start
for(unsigned int i=0; i < tip2.size(); ++i) {
cout << tip2[i] << endl;
}
}
| © 1997 Gottfried Rudorfer, C++-AG, Lehrveranstaltungen, Abteilung für Angewandte Informatik, Wirtschaftsuniversität Wien, 12/1/1998 |