cpp std::string words = "This is the end, my only friend!"; std::vector<std::string> swv;
boost::split(swv, words, boost::is_any_of(" ")); std::reverse(swv.begin(), swv.end());
std::string newwords = (std::for_each(swv.begin(), swv.end(), StringTAndJ())).value();
#include <string>
#include <algorithm>
#include <vector>
#include "boost/algorithm/string.hpp"
typedef void(*Func)(std::string&);
struct StringTAndJ
{
StringTAndJ(Func func = NULL, const std::string& sep = " ") : func_(func), sep_(sep) {}
void operator()(std::string& s) { if (func_) func_(s); word_.append(s).append(sep_); }
std::string value() { return word_; }
Func func_; std::string word_, sep_;
};
int main()
{
std::string words = "This is the end, my only friend!"; std::vector<std::string> swv;
boost::split(swv, words, boost::is_any_of(" ")); std::reverse(swv.begin(), swv.end());
std::string newwords = (std::for_each(swv.begin(), swv.end(), StringTAndJ())).value();
std::cout << newwords << std::endl;
}