Руководство по стандартной библиотеке шаблонов STL

       

int main


#include <iostream.h> #include <stl.h>

int main () { int i = min (4, 7); cout << "min (4, 7) = " << i << endl; char c = max ('a', 'z'); cout << "max ('a', 'z') = " << c << endl; return 0; }



#include <iostream.h> #include <stl.h>

int i [] = { 1, 4, 2, 8, 2, 2 };

int main () { int n = 0; // Must be initialized, as count increments n. count (i, i + 6, 2, n); cout << "Count of 2s = " << n << endl; return 0; }



#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; }



#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; }



#include <iostream.h> #include <stl.h>

int main () { list<int> years; years.push_back (1962); years.push_back (1992); years.push_back (2001); years.push_back (1999); sort (years.begin (), years.end ()); // Causes linker error. list<int>::iterator i; for (i = years.begin (); i != years.end (); i++) cout << *i << endl; return 0; }


Содержание раздела