Is there a more simple method to copy Buf into str?
Buf is a binary string.
Code:void function(string & str) { int iWholeSize = 512; char * Buf = new char[iWholeSize]; .... operations on Buf string s(Buf, Buf + iWholeSize); str = s; }
Is there a more simple method to copy Buf into str?
Buf is a binary string.
Code:void function(string & str) { int iWholeSize = 512; char * Buf = new char[iWholeSize]; .... operations on Buf string s(Buf, Buf + iWholeSize); str = s; }
Using Windows 10 with Code Blocks and MingW.
Why are you using the character array for Buf? Why not just use a string?
Jim
Because I use the function recv() that takes a char*.
Using Windows 10 with Code Blocks and MingW.
If you insure Buf is a properly terminated C-string you could just use the assignment operator.
But if Buf is not a C-string then using the constructor is best. But your constructor looks incorrect. Shouldn't it be:Code:str = Buf;
;Code:string s(Buf, value_returned_from_recv_calls);
You could also avoid the temp variable with:
JimCode:str = string(Buf, value_returned_from_recv_calls);
Or better yet:Originally Posted by jimblumberg
Code:str.assign(Buf, value_returned_from_recv_calls);
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Great, thanks for both of you! :-)
Using Windows 10 with Code Blocks and MingW.