Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // STL05.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <vector>
- #include <functional>
- #include <algorithm>
- #include <iostream>
- #include <fstream>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- bool twice ( int elem1, int elem2 )
- {
- return elem1 * 2 == elem2;
- }
- bool less10 ( int elem1 )
- {
- return elem1 <10;
- }
- void show(int x) { cout << setw(8) << x << endl; };
- //void show(int x) { cout << setw(8) << x << endl; };
- int _tmain(int argc, _TCHAR* argv[])
- {
- vector<int> a;
- vector<int>::iterator result1;
- ifstream ifs("file_a.txt");
- int x;
- while (ifs>> x)
- {
- a.push_back (x);
- }
- //adjacent_find
- result1 = adjacent_find( a.begin( ), a.end( ) );
- if ( result1 == a.end( ) )
- cout << "There are not two adjacent elements that are equal."
- << endl;
- else
- cout << "There are two adjacent elements that are equal."
- << "\n They have a value of "
- << *( result1 ) << "." << endl;
- //count
- cout << "Elements =10 -->" << count(a.begin(), a.end(), 10) << endl;
- //count_if
- cout << "Elements <10 -->" << count_if(a.begin(), a.end(), bind2nd (less <int>(), 10)) << endl;
- cout << "Elements <10 -->" << count_if(a.begin(), a.end(), less10) << endl;
- //equal 1
- vector <int> b(a);
- if (equal(a.begin(),a.end(),b.begin ()))
- cout << "a==b" << endl;
- else
- cout << "a!=b" << endl;
- //equal 2
- vector <int> c,d;
- c.push_back (1);
- c.push_back (2);
- c.push_back (3);
- d.push_back (2);
- d.push_back (4);
- d.push_back (6);
- if (equal(c.begin(),c.end(),d.begin (),twice))
- cout << "c==d" << endl;
- else
- cout << "c!=d" << endl;
- //find
- result1 = find(a.begin(),a.end(),37) ;
- if (result1==a.end()) cout << "Not found" << endl;
- else
- cout << *(result1) << endl;
- //find
- result1 = find_if(a.begin(),a.end(),less10);
- if (result1==a.end()) cout << "Not found" << endl;
- else
- cout << *(result1) << endl;
- //for_each(a.begin(),a.end (), show);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement