Check to see if string is a substring of another.

I'm new to this language and i need a little help. The question asked is to use this function (int indexOf(const string& s1, const string& s2)) to check whether string s1 is a substring of s2. If its a match return the 1st index in s2 and if not return -1. Then it says to right a program that reads the strings.

[code]
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int indexOf(const string& s1, const string& s2)
{
if (s2.find(s1))
{
return s2.length();
}

else
{
return -1;
}
}



int main()
{

cout << "Enter the first string: ";
string s1[10];
getline(cin, s1[10]);

cout << "Enter the second string: ";
string s2[10];
getline(cin, s2[10]);

int answer = indexOf(s1[10], s2[10]);

cout << answer << endl;



system("PAUSE");
return EXIT_SUCCESS;
}
[code]
Topic archived. No new replies allowed.