본문 바로가기
프로그래밍 기록/stl

find

by hominic 2023. 12. 9.
728x90
반응형
반응형
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;


void main()
{
int ari[]={1,2,3,4,5};
vector<int> vi(&ari[0],&ari[5]);
list<int> li(&ari[0],&ari[5]);

puts(find(vi.begin(),vi.end(),4)==vi.end() ? "없다.":"있다.");
puts(find(li.begin(),li.end(),8)==li.end() ? "없다.":"있다.");
puts(find(&ari[0],&ari[5],3)==&ari[5] ? "없다.":"있다.");
}







void main()
{
string names[]={"김씨","구씨","문씨",
"김씨","임씨","영씨","박씨"};
vector<string> as(&names[0],&names[7]);

vector<string>::iterator it;
it=find(as.begin(),as.end(),"이씨");
if (it==as.end()) {
cout << "없다" << endl;
} else {
cout << "있다" << endl;
}
}





void main()
{
string names[]={"김씨","구씨","문씨",
"김씨","임씨","영씨","박씨"};
vector as(&names[0],&names[7]);

vector<string>::iterator it;
for (it=as.begin();;it++) {
it=find_if(it,as.end(),HasYoung);
if (it==as.end()) break;
cout << *it << "이(가) 있다." << endl;
}
}

 

 

find_first_of

void main()
{
	int ar1[]={3,1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3};
	int ar2[]={2,4,6,8,0};

	int *p=find_first_of(&ar1[0],&ar1[25],&ar2[0],&ar2[4]);
	if (p!=&ar1[25]) {
		printf("최초의 짝수는 %d번째의 %d입니다.\n",p-ar1,*p);
	}
}
728x90
반응형

'프로그래밍 기록 > stl' 카테고리의 다른 글

reverse  (0) 2023.12.09
sort  (0) 2023.12.09
itergeneric  (0) 2023.12.09
itervector  (0) 2023.12.08
iterarray  (0) 2023.12.08

댓글