string return a substring possibly with .find() [closed]

Not sure what it is that is not compiling for you, but this is what you want:

string over = yay.substr(yay.find("over"),4);

To break it down: yay.find(“over”) returns index of the first letter of “over” in ‘yay’, which is 16. yay.substr(16,4) extracts 4 characters from ‘yay’ starting at index 16.

string over = yay.find("over");

Does not work because yay.find does not return a string, it returns an index

Leave a Comment