Isn't char always 1 byte?
What I'm trying to achieve is to take a part of a packet and transfer it to another packet.
And sf::Packet stores it's data in an std::vector<char>.
So it wanted to extract it char-wise, which is not possible.
I more or less solved it by reading to unsigned chars and casting to char, but I'm not 100% sure, if this is portable without problems.
Why there is no operator<< or operator>> for char?
Edit:
That's the code I used:
int size;
packet >> size;
if(size == 0)
{
return;
}
char * data = new char[size];
for(int i = 0; i < size; ++i)
{
unsigned char c;
packet >> c;
data[i] = static_cast<char>(c);
}
data_.Append(data, size);
delete[] data;
I can't do it just with a single append, because I can't get the current readpos (as it's private)
Note that the "string" here is not zero terminated and may contain zeros in the middle