A good example for boost::algorithm::join

I recently wanted to use boost::algorithm::join but I couldn't find any usage examples and I didn't want to invest a lot of time learning the Boost Range library just to use this one function.

Can anyone provide a good example of how to use join on a container of strings? Thanks.

82401 次浏览
#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!
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"