int main() {
const unsigned count = sizeof(labels) / sizeof(labels[0]);
ostream_iterator‹char*› iter(cout);
copy(labels, labels + count, iter);
cout ‹‹ endl;
unique(labels, labels + count, str_equal);
copy(labels, labels + count, iter);
cout ‹‹ endl;
return 0;
}
parsrtc1.cpp
#include ‹stl.h›
#include ‹stdlib.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(10);
for (int i = 0; i ‹ v1.size(); i++) v1[i] = rand() % 10;
vector‹int› result(5);
ostream_iterator‹int› iter(cout, ' ');
copy(v1.begin(), v1.end(), iter);
cout ‹‹ endl;
partial_sort_copy(v1.begin(), v1.end(), result.begin(), result.end());
copy(result.begin(), result.end(), iter);
cout ‹‹ endl;
return 0;
}
equal1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(10);
for (int i = 0; i ‹ v1.size(); i++) v1[i] = i;
vector‹int› v2(10);
if (equal(v1.begin(), v1.end(), v2.begin())) cout ‹‹ 'v1 is equal to v2' ‹‹ endl;
else cout ‹‹ 'v1 is not equal to v2' ‹‹ endl;
copy(v1.begin(), v1.end(), v2.begin());
if (equal(v1.begin(), v1.end(), v2.begin())) cout ‹‹ 'v1 is equal to v2' ‹‹ endl;
else cout ‹‹ 'v1 is not equal to v2' ‹‹ endl;
return 0;
}
equal0.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers1[5] = {1, 2, 3, 4, 5};
int numbers2[5] = {1, 2, 4, 8, 16};
int numbers3[2] = {1, 2};
int main() {
if (equal(numbers1, numbers1 + 5, numbers2))
cout ‹‹ 'numbers1 is equal to numbers2' ‹‹ endl;
else cout ‹‹ 'numbers1 is not equal to numbers2' ‹‹ endl;
if (equal(numbers3, numbers3 + 2, numbers1))
cout ‹‹ 'numbers3 is equal to numbers1' ‹‹ endl;
else cout ‹‹ 'numbers3 is not equal to numbers1' ‹‹ endl;
return 0;
}
genern2.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹stdlib.h›
class Fibonacci {
public:
Fibonacci(): v1(0), v2(1) {}
int operator() ();
private:
int v1;
int v2;
};
int Fibonacci::operator() () {
int r = v1 + v2;
v1 = v2;
v2 = r;
return v1;
}
int main() {
vector‹int› v1(10);
Fibonacci generator;