Skip to content

C++ std::string to vector<char> and vector<char> to std::string #33

Open
@Shellbye

Description

@Shellbye

接上回( #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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions