// Compile this code without defining OS_USE_EXCEPTIONS.
void my_handler(int code_, const char* str_) {
cout ‹‹ 'Caught ' ‹‹ str_ ‹‹ '[code ' ‹‹ code_ ‹‹ ']' ‹‹ endl;
}
int main() {
os_handler_function_t old_h = os_set_error_handler(my_handler);
vector‹int› v;
v.pop_back(); // Generates an empty object error.
cout ‹‹ 'returned from pop_back()' ‹‹ endl;
os_set_error_handler(old_h);
v.pop_back(); // Generates an empty object error.
cout ‹‹ 'successful termination' ‹‹ endl;
return 0;
}
incl0.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] = {4, 8};
int main() {
if (includes(numbers1, numbers1 + 5, numbers3, numbers3 + 2))
cout ‹‹ 'numbers1 includes numbers3' ‹‹ endl;
else cout ‹‹ 'numbers1 does not include numbers3' ‹‹ endl;
if (includes(numbers2, numbers2 + 5, numbers3, numbers3 + 2))
cout ‹‹ 'numbers2 includes numbers3' ‹‹ endl;
else cout ‹‹ 'numbers2 does not include numbers3' ‹‹ endl;
return 0;
}
setdiff2.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹string.h›
char* word1 = 'ABCDEFGHIJKLMNO';
char* word2 = 'LMNOPQRSTUVWXYZ';
int main() {
ostream_iterator‹char› iter(cout, ' ');
cout ‹‹ 'word1: ';
copy(word1, word1 + ::strlen(word1), iter);
cout ‹‹ '
word2: ';
copy(word2, word2 + ::strlen(word2), iter);
cout ‹‹ endl;
set_difference(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), iter, less‹char›());
cout ‹‹ endl;
return 0;
}
setunon2.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹string.h›
char* word1 = 'ABCDEFGHIJKLMNO';
char* word2 = 'LMNOPQRSTUVWXYZ';
int main() {
ostream_iterator‹char› iter(cout, ' ');
cout ‹‹ 'word1: ';
copy(word1, word1 + ::strlen(word1), iter);
cout ‹‹ '
word2: ';
copy(word2, word2 + ::strlen(word2), iter);
cout ‹‹ endl;
set_union(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), iter, less‹char›());
cout ‹‹ endl;
return 0;
}
unique2.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹string.h›
bool str_equal(const char* a_, const char* b_) {
return ::strcmp(a_, b_) == 0 ? 1: 0;
}
char* labels[] = {'Q','Q','W','W','E','E','R','T','T','Y','Y'};