I was trying to output a not null terminated char array to a file.
Actual thing is, I am receiving packets and then printing their fields.
Now as these field
If you want to put exactly maxbytes bytes, use write method
maxbytes
write
stream.write(buffer, maxbytes);
If you can have less bytes in buffer, how do you know how many of them your buffer contains? If '\0' marks buffer end, you can write:
'\0'
stream.write(buffer, std::find(buffer, buffer+maxbytes, '\0') - buffer);