The code will get two string from user and checks the string , includes substring as the second input or not.
string st1;
string subst1;
string message = " ";
cout << "Enter string and subst:";
cin >> st1;
cin >> subst1;
for (int a=0; a < st1.length(); a++) {
if (st1[a] == subst1[0]) {
for (int k = 0; k < subst1.length(); k++) {
if (st1[a + k] == subst1[k])
message = "True";
else
message = "False";
}
}
}
cout << message;
This code does not work inputs like "alice" and "ba". The output should be false but when I execute the code program directly ended
str1[a] == subst1[0]astruethenmessagewill not get set to false and subsequently gets left as the single white space. It would work for say,AliceandAbba.