I wondered about the following problem: suppose I have a C-style function that reads raw data into a buffer
int recv_n(int handle, void* buf, size_t len);
Can I read data directly in std:string or stringstream without allocating temporary buffers? For instance,
std::string s(100, '\0'); recv_n(handle, s.data(), 100);
I think this solution has the result undefined, because afaik, string::c_str and string::data can return a temporary location and do not have to return a pointer to the real place in memory used by the object to store the data.
Any ideas?
source share