title: Sending Unicode (win32) text packets over the network using winsock?
body: <p>I am trying to send text packets over the network using winsock. However the text is stored as wchar_t and I need to be able to convert the text into byte (char) format for sending over the network, which will then be converted back to wchar_t.</p>
  
  <p>I've experimented with using ostringstream and have converted the wchar_t string of mine to what looks like byte format, however when I try to go the reverse I get a load of gibberish.</p>
  
  <p>I can't seem to find any answers whilst looking online, so any help would be much appreciated.</p>
  
  <p>OK here is some code that I played with. </p>
  
  <pre><code>std::wstring text( ieS("Hello") );
  std::ostringstream ostr;
  ostr.imbue( std::locale( ) );
  ostr &lt;&lt; text.c_str();
  std::string text2 = ostr.str();
  </code></pre>
  
  <p>Convert to std::string to get char format.</p>
  
  <pre><code>std::wostringstream wostr;
  wostr.imbue( std::locale( ) );
  wostr &lt;&lt; text2.c_str();
  text = oss.str(); // gibberish
  </code></pre>
  
  <p>Convert back to std::wstring to get wchar_t format...</p>