在C++中将std::vector在不经过for遍历的前提下转为string
- accumulate函数
#include <vector>
#include <string>
#include <numeric> //accumulate需要
#include <iostream>
int main()
{
std::string str;
std::vector<std::string> list;
list.push_back("hello");
list.push_back("world");
str = accumulate(list.begin(), list.end(), str);
std::cout<<str.c_str()<<std::endl;
}
// 输出
helloworld