Shellbye.github.io
Shellbye.github.io copied to clipboard
C++ std::string to vector<char> and vector<char> to std::string
接上回( #32 ),可以把转成vector<char>的二进制文件进一步转成std::string:
std::string str = "This is a test";
std::cout << str << std::endl;
std::vector<char> vc(str.begin(), str.end());
for (auto c : vc) {
std::cout << c << std::endl;
}
std::string str2(vc.begin(), vc.end());
std::cout << str2 << std::endl;
The output is:
This is a test
T
h
i
s
i
s
a
t
e
s
t
This is a test