предшествующий принятию стандарта синтаксис
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
// предшествующий принятию стандарта синтаксис <iostream>
#include <iostream.h>
class GreaterThan {
public:
GreaterThan( int size = 6 ) : _size( sz ){}
int size() { return _size; }
bool operator()(const string &s1)
{ return s1.size() > _size; }
private:
int _size;
};
class PrintElem {
public:
PrintElem( int lineLen = 8 )
: _line_length( lineLen ), _cnt( 0 )
{}
void operator()( const string &elem )
{
++_cnt;
if ( _cnt % _line_length == 0 )
{ cout << '\n'; }
cout << elem << " ";
}
private:
int _line_length;
int _cnt;
};
class LessThan {
public:
bool operator()( const string & s1,
const string & s2 )
{ return s1.size() < s2.size(); }
};
typedef vector<string, allocator> textwords;
void process_vocab( vector<textwords, allocator> *pvec )
{
if ( ! pvec ) {
// вывести предупредительное сообщение
return;
}
vector< string, allocator > texts;
vector<textwords, allocator>::iterator iter;
for ( iter = pvec->begin() ; iter != pvec->end(); ++iter )
copy( (*iter).begin(), (*iter).end(),
back_inserter( texts ));
// отсортировать вектор texts
sort( texts.begin(), texts.end() );
// теперь посмотрим, что получилось
for_each( texts.begin(), texts.end(), PrintElem() );
cout << "\n\n"; // разделить части выведенного текста
// удалить дубликаты
vector<string, allocator>::iterator it;
it = unique( texts.begin(), texts.end() );
texts.erase( it, texts.end() );
// посмотрим, что осталось
for_each( texts.begin(), texts.end(), PrintElem() );
Содержание Назад Вперед