title: Store a string in a vector of unsigned long int
body: <p>I would like to convert a <code>std::string</code> into a <code>std::vector&lt;unsigned long int&gt;</code>, and be able to reverse it. Currently, I do this by this way :</p>
  
  <pre><code>std::string str = "Hello World !";
  std::vector&lt;unsigned long int&gt; keys;
  for(unsigned long int i = 0; i &lt; str.length();)
  {
    unsigned long int key = 0;
    for(unsigned long int j = 0; j &lt; sizeof(unsigned long int) &amp;&amp; i &lt; str.length(); ++i,++j)
    {
      unsigned char uchar_value = static_cast&lt;unsigned char&gt;(str[i]);
      unsigned long int ulong_value = static_cast&lt;unsigned long int&gt;(uchar_value);
      key |= ulong_value &lt;&lt; (j * CHAR_BIT);
    }
    keys.push_back(key);
  }
  </code></pre>
  
  <p>Then, I have a similar procedure to reverse it. But it's quite ugly ! <strong>Is there a better/more elegant way to do it ?</strong> Maybe directly with <code>memcpy</code> ? But I don't see how.</p>