template <class T>
std::string join(T& val, std::string delim)
{
std::string str;
typename T::iterator it;
const typename T::iterator itlast = val.end()-1;
for (it = val.begin(); it != val.end(); it++)
{
str += *it;
if (it != itlast)
{
str += delim;
}
}
return str;
}
打印容器中的字符串
#include <iostream>
#include <algorithm>
copy(c.cbegin(), c.cend(),
ostream_iterator<std::string>(cout, "'\n"))