Suppose I have a vector<int>
and I want to convert it into string, what should I do?
What I got from searching on the internet is
std::ostringstream oss;
if (!vec.empty())
{
// Convert all but the last element to avoid a trailing ","
std::copy(vec.begin(), vec.end()-1,
std::ostream_iterator<int>(oss, ","));
// Now add the last element with no delimiter
oss << vec.back();
}
But I cannot understand what it means or how it works. Is there any other simple to understand way?