⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io20_6.04.c

📁 C++ Primer的第三版结合了Stanley Lippman的实践经验和Josée Lajoie对于ANSI/ISO标准C++的深入理解。这本指导书的第三版已经被重新改写过
💻 C
字号:
// #include <fstream>
#include <fstream.h>
#include <iterator>
#include <vector>
#include <algorithm>

/* 
 * generates:

A Alice Daddy Emma Her I Shyly a 
alive almost asks at beautiful bird blows but 
creature fiery flight flowing hair has he her 
him in is it like long looks magical 
mean more no red same says she shush 
such tell tells the there through time to 
untamed wanting when wind 
*/

template <class InputIterator>
void filter_string( InputIterator first, InputIterator last,
                    string filt_elems = string("\",."))
{
        for ( ; first != last; first++ )
        {
                string::size_type pos = 0;
                while (( pos = (*first).find_first_of( filt_elems, pos ))
                            != string::npos )
                                (*first).erase( pos, 1 );
        }
}

int main() 
{
	ifstream infile( "alice_emma" );

	istream_iterator<string> ifile( infile );
	istream_iterator<string> eos;

	vector< string > text;
	copy( ifile, eos, inserter( text, text.begin() ));

	string filt_elems( "\",.?;:" );
	filter_string( text.begin(), text.end(), filt_elems );

	vector<string>::iterator iter;

	sort( text.begin(), text.end() );
	iter = unique( text.begin(), text.end() );
	text.erase( iter, text.end() );
	
	ofstream outfile( "alice_emma_sort" );

	iter = text.begin();
	for ( int line_cnt = 1; iter != text.end(); ++iter, ++line_cnt ) 
	{
		outfile << *iter << " ";
		if ( ! ( line_cnt % 8 ))
	     		outfile << '\n';
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -