1.string转vector
#include#include#include#includeusing namespace std;int main(){
string str = "hello world!";
vector<uint8_t> vec;
vec.assign(str.begin(), str.end());
for(size_t i=0; i<vec.size(); i++){
cout<<vec[i]<<" ";
}
cout<<endl;
return 0;}
2.vector转string
#include#include#include#includeusing namespace std;int main(){
string str;
vector<char> vec={'a','a','a','b','a'};
str.assign(vec.begin(), vec.end());
cout<<str<<endl;
// vector转 string
string str2;
vector<string> vec2{"hhh", "zzz"};
str2 = accumulate(vec2.begin(), vec2.end(), str2);
cout<<"str2 = "<<str2<<endl;
return 0;}