All I've found is boost::algorithm::string::join. However, it seems like overkill to use Boost only for join. So maybe there are some time-tested recipes?
UPDATE:
Sorry, the question caption were bad.
I'm looking for method to concatenate strings with separator, not just to concatenate one-by-one.
解决方案
Since you're looking for a recipe, go ahead and use the one from Boost. Once you get past all the genericity, it's not too complicated:
Allocate a place to store the result.
Add the first element of the sequence to the result.
While there are additional elements, append the separator and the next element to the result.
Return the result.
Here's a version that works on two iterators (as opposed to the Boost version, which operates on a range.
template
std::string join(Iter begin, Iter end, std::string const& separator)
{
std::ostringstream result;
if (begin != end)
result << *begin++;
while (begin != end)
result << separator << *begin++;
return result.str();
}