I declared a large character array and then I subsequently read from a socket to populate it.
boost::array<char, 32841> buf{}
size_t len = boost::asio::read(socket, aio::buffer(buf, 32841));
If I print out len
I correctly get 32841 and when I loop through all the character in the array individually, like so,
for (char i : buf) {
std::cout << i << std::endl;
}
I get an output for each character. However, when I try to print out the string form of my buffer (via buf.data()
), things don't work as I would like them to. I don't get all the characters to print out -- only around 20 characters print out.
I am reading a bunch of encrypted junk (for example, �Q{��=� �o$9�ZC �kL
) into the buffer which means that there is the possibility to get chars that encode all sorts of funky characters like null bytes, new lines, etc. Could this be my issue? Does .data()
stop string conversion at null bytes or some other weird character?