-edit- I am sending binary and not a string. My test is using html pages so in this example i am only using a string but my question is about binary, vectors and debugging with ostream. I make this clears some confusion.
I have the following code:
cout << string(&v[0]).substr(0, len);
Is there a better way to print the string v with cout up the length len? I thought of doing v[len] = 0 but I an assertion is thrown with a size of 1. My code is:
vector<char> v;
v.reserve(1024*16); //required
v.resize(1); //so we can do &v[0]
recv(sockfd, &v[0], v.capacity(), 0);
while (l > 0)
{
cout << string(&v[0]).substr(0, l);
recv(sockfd, &v[0], v.capacity(), 0);
}
cout << "the size is " << v.size();