1.string转vector
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using 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;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/cb7d500d71aeccb0f570d2db8bc32456.png)
2.vector转string
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
string str;
vector<char> vec={'a','a','a','b','a'};
str.assign(vec.begin(), vec.end());
cout<<str<<endl;
string str2;
vector<string> vec2{"hhh", "zzz"};
str2 = accumulate(vec2.begin(), vec2.end(), str2);
cout<<"str2 = "<<str2<<endl;
return 0;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9a3be8eb08e6fc8320c8386a7a08a4af.png)