Using the code in my original post putting a breakpoint at the end this is what sFormatted looks like:
What has happened is the _AddInt function has added 4 bytes of data belonging to an integer which is in this case '1'. The integer takes up elements [0][1][2][3] and [1][2][3] are null characters.
With small integers, it seems that not all of the bytes contain data; in this case only one bytes is used. The null characters are needed because at the other end when _GetInt is used, the receiving end must know the size of the data it is getting; thus the size is fixed at 4 bytes for integers regardless of whether it uses all of them or not. The bytes that are not used are set to null.
The reason for this is to create a way of formulating packets for networking; the idea is as follows:
At the sending end..
-Add integer to buffer
-Send buffer
Then at the receiving end..
-Receive buffer
-Get integer from buffer
The way I see it I have the following options:
-Replace the null characters with something else for sending, and then convert the c string to a std string and put the null characters back in when received.
-Allocate a different type of memory to the WSABUF structure (instead of C strings).
-Find a way to tell C strings that I don't want null terminating characters to indicate the end of the string.
I don't know if any of those are possible, or if they would work.