Created
December 8, 2010 22:16
-
-
Save NewbiZ/734015 to your computer and use it in GitHub Desktop.
Join a container of strings into a single one, with a delimiter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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