boost::join函数
template< typename SequenceSequenceT, typename Range1T>
inline typename range_value<SequenceSequenceT>::type
join(const SequenceSequenceT& Input,const Range1T& Separator)
- Input:是一个包含string类型的容器
- Separator: 一个分隔连接段的字符串
- 返回值:返回一个连接后的字符串
代码
#include <iostream>
#include <string>
#include <vector>
#include <boost/algorithm/string/join.hpp>
int main()
{
std::vector<std::string> vct_str;
vct_str.push_back("123");
std::string str2 = boost::join(vct_str,",");
std::cout<<"str2="<<str2<<std::endl;
vct_str.push_back(456);
std::string str3 = boost::join(vct_str,",");
std::cout<<"str3="<<str3<<std::endl;
return 0;
}
[banting@localhost teset]$ g++ -g test4.cpp -L/usr/local/lib -lboost_system -o test4
[banting@localhost teset]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATHP:/usr/local/lib
[banting@localhost teset]$
str2=123
str3=123,456