I need to send data to server as binary... My program used to be in c, now im changing it to c++..

Lets say I have:
unsigned short first = 0; (short size is 2 bytes)
unsigned short second = 1; -> I would swap this in c with htons(1)

How I could do it in c would be to put both in a packed struct and then cast to char.
(put both together in a char string to get):
unsigned char request[128] = {0,0, 0,1 } --> 2 x 2 bytes

Now the question... How should I do this with STL string? What would be the right way to swap int, short, long.. like with htons (htons, htonl)?

string request;

I want to get request "0001"; - I think I can do that since string is not NULL terminated?

I have some program that uses class to do this with CString (which I dont know) with << operator. Heres the source:

	void operator << (unsigned __int8 c)
		Append((BYTE *)&c,1);

	void operator << (unsigned __int16 c)
		c = htons(c);
		Append((BYTE *)&c,2);

	void operator << (unsigned __int32 c)
		c = htonl(c);
I would consider this way, but Im not sure if its the best.. I think it would be better to use templated class, but im not sure how should I do it..

Thanks a lot for help