You're almost right, but failing to account for the fact that cout << what.position() << ", ";
will output the matching string's position relative to the end of the last matching string, ie s
.
Since s
knows exactly where it is in relation to input
, this should work:
cout << ((s - input.begin()) + what.position()) << ", ";