title: C++ How to Marshal data types like integers and floats into a string of bytes?
body: <p>Getting into socket programming with C++, and I'd like to find a way to marshal a series of data types into a string of bytes to be sent over a network via a socket using UDP.</p>
  
  <p>Here's the method header</p>
  
  <pre><code>char * Message::marshal( int &amp;n)
  </code></pre>
  
  <p>and the series of data types I need to marshal are:</p>
  
  <pre><code>int int int int float  //need to be all marshaled into the same byte string
  </code></pre>
  
  <p>The length is saved to n, and the string of bytes is returned in a character array.  I'd also like to know how to unmarshal that string of bytes as well.</p>
  
  <p>The server I'm working on most likely doesn't have boost library, and is probably not updated to C++ 11.  The last server I was in wasn't, so I'm going to assume they didn't update them yet.</p>
  
  <p>One method of serializing I saw was using streams, but I saw something about non portability (I'm writing the source code in windows, and then I'll change a few things for unix and compile it on the unix server).</p>
  
  <p>I need to use standard C++ library stuff as again I have no control over the server.</p>