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?
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:
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();
}