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

📄 alg46.c

📁 C++ PRIME书中的原代码,看本书时可以学习的例子.
💻 C
字号:
#include <algorithm>
#include <vector>
#include <iostream.h>

/* generates:
Expecting to find the substring `ate': a t e 
Expecting to find the substring `vat': v a t 
*/

int main() 
{
        ostream_iterator< char >  ofile( cout, " " );
	
	char str[ 25 ]   = "a fine and private place";
	char substr[] = "ate";
		
	char *found_str = search(str,str+25,substr,substr+3);

	cout << "Expecting to find the substring `ate': ";
        copy( found_str, found_str+3, ofile ); cout << '\n';
		
	vector< char, allocator > vec( str, str+24 );
	vector< char, allocator > subvec(3);

	subvec[0]='v'; subvec[1]='a'; subvec[2]='t';
	
	vector< char, allocator >::iterator iter; 
        iter = search( vec.begin(), vec.end(),
		       subvec.begin(), subvec.end(),
		       equal_to< char >() );
		
	cout << "Expecting to find the substring `vat': ";
        copy( iter, iter+3, ofile ); cout << '\n';

}

⌨️ 快捷键说明

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