01.
#include <iostream>
02.
#include <string>
03.
#include <vector>
04.
05.
using
namespace
std;
06.
07.
bool
in_array(
const
string
&needle,
const
vector<
string
> &haystack);
08.
09.
int
main(
int
argc,
char
*argv[])
10.
{
11.
12.
vector<
string
> custom;
13.
14.
custom.push_back(
"Apple"
);
15.
custom.push_back(
"Orange"
);
16.
custom.push_back(
"Cherry"
);
17.
18.
if
(in_array(
"Grape"
, custom))
19.
cout <<
"Grape in list"
<<endl;
20.
else
21.
cout <<
"Grape not found"
<<endl;
22.
23.
if
(in_array(
"Orange"
, custom))
24.
cout <<
"Orange in list"
<<endl;
25.
else
26.
cout <<
"Orange not found"
<<endl;
27.
return
0;
28.
}
29.
30.
bool
in_array(
const
string
&needle,
const
vector<
string
> &haystack)
31.
{
32.
int
max=haystack.size();
33.
34.
if
(max==0)
return
false
;
35.
36.
for
(
int
i=0; i<max; i++)
37.
if
(haystack[i]==needle)
38.
return
true
;
39.
return
false
;
40.
}