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

Менг Ли

Шрифт:

‹‹ " to before index " ‹‹ (range.second - numbers) ‹‹ endl;

 return 0;

}

advance.cpp

#include ‹stl.h›

#include ‹iostream.h›

int main {

 typedef vector‹int› IntVector;

 IntVector v(10);

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

 IntVector::iterator location = v.begin;

 cout ‹‹ "At Beginning: " ‹‹ *location ‹‹ endl;

 advance(location, 5);

 cout ‹‹ "At Beginning + 5: " ‹‹ *location ‹‹ endl;

 return 0;

}

replace1.cpp

#include ‹stl.h›

#include ‹iostream.h›

int main {

 vector‹int› v1(10);

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

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

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

 cout ‹‹ endl;

 replace(v1.begin, v1.end, 2, 42);

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

 cout ‹‹ endl;

 return 0;

}

alg3.cpp

#include ‹iostream.h›

#include ‹stl.h›

int main {

 vector‹int› i;

 i.push_back(1);

 i.push_back(4);

 i.push_back(2);

 i.push_back(8);

 i.push_back(2);

 i.push_back(2);

 int n = 0; // Must be initialized, as count increments n.

 count(i.begin, i.end, 2, n);

 cout ‹‹ "Count of 2s = " ‹‹ n ‹‹ endl;

 return 0;

}

func2.cpp

#include ‹iostream.h›

#include ‹stl.h›

bool bigger_than(int x_, int y_) {

 return x_ › y_;

}

int main {

 vector‹int›v;

 v.push_back(4);

 v.push_back(1);

 v.push_back(5);

 sort(v.begin, v.end, bigger_than);

 vector‹int›::iterator i;

 for (i = v.begin; i != v.end; i++) cout ‹‹ *i ‹‹ endl;

 return 0;

}

unegate1.cpp

#include ‹iostream.h›

#include ‹stl.h›

struct odd: public unary_function‹int, bool› {

 odd {}

 bool operator (int n_) const {return (n_ % 2) - 1;}

};

int array[3] = {1, 2, 3};

int main {

 int* p = find_if(array, array + 3, unary_negate‹odd›(odd));

 if (p != array + 3)

 cout ‹‹ *p ‹‹ endl;

 return 0;

}

alg4.cpp

#include ‹iostream.h›

#include ‹stl.h›

int main {

 vector‹int› years;

 years.push_back(1962);

 years.push_back(1992);

 years.push_back(2001);

 years.push_back(1999);

 sort(years.begin, years.end);

 vector‹int›::iterator i;

 for (i = years.begin; i!= years.end; i++)

 cout ‹‹ *i ‹‹ endl;

 return 0;

}

countif1.cpp

#include ‹stl.h›

#include ‹iostream.h›

  • Читать дальше
  • 1
  • ...
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • ...

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

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

  • Моя полка

Контакты

  • chitat.ebooker@gmail.com

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