Skip to content

Instantly share code, notes, and snippets.

@NewbiZ
Created December 8, 2010 22:16
Show Gist options
  • Save NewbiZ/734015 to your computer and use it in GitHub Desktop.
Save NewbiZ/734015 to your computer and use it in GitHub Desktop.
Join a container of strings into a single one, with a delimiter
namespace
{
struct add_delimiter
{
add_delimiter( const std::string& d )
{ delimiter = d; }
std::string operator()( const std::string& lhs, const std::string& rhs )
{ return lhs + (lhs.empty() ? "" : delimiter) + rhs; }
std::string delimiter;
};
}
void join( const std::vector<std::string>& list, std::string& str, const std::string delimiter="" )
{
str = std::accumulate( list.begin(), list.end(), std::string(""), add_delimiter(delimiter) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment