I won't go into much, but maybe this gets you started. Always try to start from the simplest version of the problem. I see something like this:
#include <string>
using namespace std;
int findSchoolEnd(const string & str) {
size_t pos = str.find("xyxabc");
if (pos == string::npos) return -1;
return pos + string("xyxabc").length();
}
int findStudentBegin(const string & str) {
size_t pos = str.find("xyz");
if (pos == string::npos) return -1;
return pos;
}
string getMiddleStuff(const string & str, size_t begin, size_t end) {
if (begin == string::npos) return "";
if (end == string::npos) return "";
return str.substr(end, begin-end);
}
int main() {
string str = "Hi i am xyxabc and i work for xyz";
size_t begin = findSchoolEnd(str);
size_t end = findStudentBegin(str);
string result = getMiddleStuff(str, end, begin);
}
Only begin working on the key comparisons after the core works, like the previous code does.
Good luck!