Вход/Регистрация
РУКОВОДСТВО ПО СТАНДАРТНОЙ БИБЛИОТЕКЕ ШАБЛОНОВ (STL)
вернуться

Менг Ли

Шрифт:

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);

 ostream_iterator‹int› iter(cout, " ");

 copy(v1.begin, v1.end, iter);

 cout ‹‹ endl;

 return 0;

}

remif1.cpp

#include ‹stl.h›

#include ‹iostream.h›

bool odd(int a_) {

 return a_ % 2;

}

int numbers[6] = {0, 0, 1, 1, 2, 2};

int main {

 remove_if(numbers, numbers + 6, odd);

 for (int i = 0; i ‹ 6; i++)

 cout ‹‹ numbers[i] ‹‹ ' ';

 cout ‹‹ endl;

 return 0;

}

foreach1.cpp

#include ‹stl.h›

#include ‹iostream.h›

void print_sqr(int a_) {

 cout ‹‹ a_ * a_ ‹‹ " ";

}

int main {

 vector‹int› v1(10);

 for (int i = 0; i ‹ v1.size; i++) v1[i] = i;

 for_each(v1.begin, v1.end, print_sqr);

 cout ‹‹ endl;

 return 0;

}

parsrtc0.cpp

#include ‹stl.h›

#include ‹iostream.h›

int numbers[6] = {5, 2, 4, 3, 1, 6};

int main {

 int result[3];

 partial_sort_copy(numbers, numbers + 6, result, result + 3);

 for (int i = 0; i ‹ 3; i++) cout ‹‹ result[i] ‹‹ ' ';

 cout ‹‹ endl;

 return 0;

}

pqueue2.cpp

#include ‹iostream.h›

#include ‹stl.h›

int main {

 priority_queue‹deque‹char*›, greater_s› q;

 q.push((char*) "cat");

 q.push((char*) "dog");

 q.push((char*) "ape");

 while (!q.empty) {

  • Читать дальше
  • 1
  • ...
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71

Ебукер (ebooker) – онлайн-библиотека на русском языке. Книги доступны онлайн, без утомительной регистрации. Огромный выбор и удобный дизайн, позволяющий читать без проблем. Добавляйте сайт в закладки! Все произведения загружаются пользователями: если считаете, что ваши авторские права нарушены – используйте форму обратной связи.

Полезные ссылки

  • Моя полка

Контакты

  • chitat.ebooker@gmail.com

Подпишитесь на рассылку: