Я хотел бы попробовать использовать std::mismatch
(documentation)
template <class InputIterator1, class InputIterator2>
pair<InputIterator1, InputIterator2>
mismatch (InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2);
Return first position where two ranges differ
Сравнивает элементы в диапазоне [first1,last1)
против тех, в диапазоне, начиная с first2
последовательно, и возвращается, когда первое несоответствие случается.
Некоторый код:
string
mismatch_string(string const & a, string const & b) {
string::const_iterator longBegin, longEnd, shortBegin;
if(a.length() >= b.length()) {
longBegin = a.begin();
longEnd = a.end();
shortBegin = b.begin();
}
else {
longBegin = b.begin();
longEnd = b.end();
shortBegin = a.begin();
}
pair< string::const_iterator, string::const_iterator > mismatch_pair =
mismatch(longBegin, longEnd, shortBegin);
return string( mismatch_pair.first, longEnd);
}
full example with outpu т выгружается в codepad.