A good example for boost::algorithm::join

Solution 1:

#include <boost/algorithm/string/join.hpp>
#include <vector>
#include <iostream>

int main()
{
    std::vector<std::string> list;
    list.push_back("Hello");
    list.push_back("World!");

    std::string joined = boost::algorithm::join(list, ", ");
    std::cout << joined << std::endl;
}

Output:

Hello, World!

Solution 2:

std::vector<std::string> MyStrings;
MyStrings.push_back("Hello");
MyStrings.push_back("World");
std::string result = boost::algorithm::join(MyStrings, ",");

std::cout << result; // prints "Hello,World"