プログラミング道場 ACM/ICPC

要素の検索

最終更新:

kit

- view
だれでも歓迎! 編集
/*
	template<class _InIt, class _Ty>
	_InIt find(_InIt _First, _InIt _Last, const _Ty& _Val)

	template<class _InIt, class _Pr>
	_InIt find_if(_InIt _First, _InIt _Last, _Pr _Pred)
*/

#include <algorithm>
#include <iostream>

using namespace std;

bool equal_d( const char & ch )
{ return ch == 'd'; }

int main()
{
	const char* s = "abcde";

	//true
	cout << ( find(s,s+5,'b')              == s+1 ? "true":"false" ) << endl;
	cout << ( find_if(s,s+5,equal_d) == s+3 ? "true":"false" ) << endl;

 	// not found
 	cout << ( find(s,s+5,'f')               == s+5 ? "not found" : "found" ) << endl;

	return 0;
}
ウィキ募集バナー