substring range in c++

  algorithm, c++, function, substring
#include <bits/stdc++.h>
using namespace std;
bool solve(string s, string t)
{
    int n = s.size();
    int m = t.size();
    for(int i = 0; i < n - 1; ++i)
    {
        for(int j = i; j < n; ++j)
        {
            string theend = s.substr(j - (t.length() - (j - i + 1)), t.length() - (j - i + 1));
            reverse(theend.begin(), theend.end());
            if(s.substr(i, j - i + 1) + theend == t)
            {
                return true;
            }
        }
    }
    return false;
}
int main()
{
    string s, t;
    cin >> s >> t;
    cout << solve(s, t);
}

but when i compile this code it returns an error: "basic_string::substr: __pos (which is 18446744073709551611) > this->size() (which is 6)". What is wrong with substr()?

Source: Windows Questions C++

LEAVE A COMMENT