I\'m trying to build a string using data elements stored in a std::list, where I want commas placed only between the elements (ie, if elements are {A,B,C,D} in list, result stri
Yet another possibility:
#include "infix_iterator.h"
#include
typedef std::list > DataItemList;
std::string Compose(DataItemList const &diList) {
std::ostringstream ret;
infix_ostream_iterator out(ret, ",");
for (item = diList.begin(); item != diList.end(); ++item)
*out++ = (*item)->ToString();
return ret.str();
}
You can get infix_iterator.h from Google's Usenet archive (or various web sites).