ref:c++ example code at bottom from http://msdn.microsoft.com/en-us/library/windows/desktop/ms740120(v=vs.85).aspx
I have a char array
char RecvBuf[1024];
which gets filled up on receiving UDP message.
How do I store it in a std::string variable like string str; so that I can return a string from my function?
Use this constructor of
std::string:Basically, if
RecvBufis a standard (text) “string”, it’s OK just to makebut this will copy all
chars, until\0is hit.And as this buffer stores raw bytes, received from a socket, you should expect
\0bytes.When you receive the data, you’ll know it’s size. So, just use