// substring.cpp
// finds a substring within a string
// uses string arrays
// Run! LIVE! On the Internet
/*
Sample output
10
16
-1
Press any key to continue
*/
#include <iostream> // not <iostream.h>
#include <string> // not <string.h>
using namespace std;
int findTerm(string, string);
int main(void)
{
int match;
string phoneList[3] =
{
"Robert Altford, +1-606-783-9345",
"Tom Clancy, +1-606-783-8345",
"Biddle Delaney, +55-50-78845"
};
match = findTerm(phoneList[0], "ford");
cout << match << endl;
match = findTerm(phoneList[2], "+55");
cout << match << endl;
match = findTerm(phoneList[2], "+49");
cout << match << endl;
return 0;
}
int findTerm(string haystack, string needle)
{
int pos;
pos = haystack.find(needle);
return pos;
}