문제

Hello everyone and thank you very much for your time.

There is a std::stringstream that needs transferred to a remote machine. The networking library allows me to construct a packet in the following method:

CreatePacket( const void * DATA, size_t DATA_SIZE )

On the receiving end the data is returned as a uint8_t*

What I cannot figure out is how to take the std::stringstream data, put it into the CreatePacket() function, then on the receiving end reconstruct a std::stringstream from the uint8_t* and doing so in the most efficient manner.

As a side note the stringstream holds binary data.

Thank you all again for your time I greatly appreciate it.

도움이 되었습니까?

해결책

Use the str() member function to obtain an std::string from the stringstream. Then use the c_str() or data() member functions to get access to the string's internal buffer.

auto s = myStringStream.str();
CreatePacket(s.data(), s.size());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top