Question

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.

Was it helpful?

Solution

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());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top