>How do I ensure that a commom element is only outputted once?
You're faking the STL algorithm, right? What it does is a merge, where only matching items are copied to the destination. Your algorithm doesn't do the same thing, and you'll have a hard time emulating that functionality with string::find. The actual algorithm would be implemented something like this:
Code:
template<typename In1, typename In2, typename Out>
Out set_intersection(In1 first1, In1 last1, In2 first2, In2 last2, Out dst)
{
while ( first1 != last1 && first2 != last2 ) {
if ( *first1 < *first2 )
++first1;
else if ( *first2 < *first1 )
++first2;
else {
*dst++ = *first1++;
++first2;
}
}
return dst;
}