cout ‹‹ endl;
return 0;
}
swprnge1.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹string.h›
int main() {
char* word1 = 'World';
char* word2 = 'Hello';
cout ‹‹ word1 ‹‹ ' ' ‹‹ word2 ‹‹ endl;
swap_ranges(word1, word1 + ::strlen(word1), word2);
cout ‹‹ word1 ‹‹ ' ' ‹‹ word2 ‹‹ endl;
return 0;
}
vec8.cpp
#include ‹iostream.h›
#include ‹stl.h›
int main() {
vector‹int› v;
cout ‹‹ 'capacity = ' ‹‹ v.capacity() ‹‹ endl;
v.push_back(42);
cout ‹‹ 'capacity = ' ‹‹ v.capacity() ‹‹ endl;
v.reserve (5000);
cout ‹‹ 'capacity = ' ‹‹ v.capacity() ‹‹ endl;
return 0;
}
plus.cpp
#include ‹iostream.h›
#include ‹stl.h›
int input1[4] = {1, 6, 11, 8};
int input2[4] = {1, 5, 2, 3};
int main() {
int total = inner_product(input1, input1 + 4, input2, 0, plus‹int›(), times‹int›());
cout ‹‹ 'total = ' ‹‹ total ‹‹ endl;
return 0;
}
remcopy1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int numbers[6] = {1, 2, 3, 1, 2, 3};
int result[6] = {0, 0, 0, 0, 0, 0};
int main() {
remove_copy(numbers, numbers + 6, result, 2);
for (int i = 0; i ‹ 6; i++) cout ‹‹ result[i] ‹‹ ' ';
cout ‹‹ endl;
return 0;
}
error2.cpp
#include ‹stl.h›
// Compile this code with the symbol OS_USE_EXCEPTIONS defined.
int main() {
vector‹int› v;
try {
v.pop_back(); // Generates an exception.
} catch (const char* str) {
cout ‹‹ 'Caught exception ' ‹‹ str ‹‹ endl;
}
return 0;
}
iterswp1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
vector‹int› v1(6);
iota(v1.begin(), v1.end(), 0);
iter_swap(v1.begin(), v1.begin() + 3);