所以我使用CallNamedPipe函数从管道中获取一些数据,这些数据被放入response_buffer中。然而,我发现的所有将response_buffer转换为字符串的方法都不起作用。
我尝试过直接将其转换为字符串,但没有成功,还有其他方法
这里有问题的代码是
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);
与其尝试将其转换为字符串,不如从一开始就将其转换成字符串。
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);