'Through which way should I convert a pointer to a buffer into a string

So I am using the CallNamedPipe function to get some data from a pipe, which is put into response_buffer. However All the methods I have found of turning that response_buffer into a string does not work.

I have tried directly converting it to a string to no avail, as well as other methods

the code in question here is

std::string word;
        string responses;
        DWORD response_length = 0xffffffff;
        msg = "\"gettrackerpose \" + std::to_string(i) + \" \" + std::to_string(-frameTime - parameters->camLatency)";
        auto msg_cstr = reinterpret_cast<LPVOID>(const_cast<char *>(msg.c_str()));
        int tracker_pose_valid;
        constexpr int BUFFER_SIZE = 512;
        char *response_buffer[BUFFER_SIZE];
        
        int success = CallNamedPipeA(
            "\\.\\pipe\\ApriltagPipeIn", // pipe name
            msg_cstr,                      // message
            msg.size(),                    // message size
            response_buffer,               // response
            BUFFER_SIZE,                   // response max size
            &response_length,              // response size
            2 * 1000                       // timeout in ms
        );
        //The problem I am having is right here, with trying to convert the buffer to a string
        std::string str(response_buffer, response_buffer + BUFFER_SIZE);
        
        std::istringstream ret(str);


Solution 1:[1]

Instead of trying to convert it to a string, just have it one from the start.

std::string response_buffer{};
response_buffer.resize(BUFFER_SIZE);

int success = CallNamedPipeA(
            "\\.\\pipe\\ApriltagPipeIn", // pipe name
            msg_cstr,                      // message
            msg.size(),                    // message size
            response_buffer.data(),         // response
            BUFFER_SIZE,                   // response max size
            &response_length,              // response size
            2 * 1000                       // timeout in ms
        );

response_buffer.resize(response_length);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Taekahn