I would like to write a function that will take an stl container (like set, vector or list) and then iterate over the contents and then append them to a string and give back the string.
Something like this.
// I dont know how to do this. Just using stl::container for meanings sake Not sure if such a thing exists?
template<typename T, typename Container = stl::container<T> >
void JoinToString(const Container<T> cont, const char * delim, string &str)
{
stringstream s;
Container<T>::const_iterator it = cont.begin, last = cont.end();
while(it != last)
{
s<<(*it);
++it;
if(it == last)
break;
s<<delim;
}
str = s.str();
}
I want something to this effect. Not sure how to write such a code.