title: How to convert wstring into string?
body: <p>The question is how to convert wstring to string?</p>
  
  <p>I have next example :</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
      std::wstring ws = L"Hello";
      std::string s( ws.begin(), ws.end() );
  
    //std::cout &lt;&lt;"std::string =     "&lt;&lt;s&lt;&lt;std::endl;
      std::wcout&lt;&lt;"std::wstring =    "&lt;&lt;ws&lt;&lt;std::endl;
      std::cout &lt;&lt;"std::string =     "&lt;&lt;s&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>the output with commented out line is :</p>
  
  <pre><code>std::string =     Hello
  std::wstring =    Hello
  std::string =     Hello
  </code></pre>
  
  <p>but without is only :</p>
  
  <pre><code>std::wstring =    Hello
  </code></pre>
  
  <p>Is anything wrong in the example? Can I do the conversion like above?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>New example (taking into account some answers) is </p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;locale&gt;
  
  int main()
  {
      setlocale(LC_CTYPE, "");
  
      const std::wstring ws = L"Hello";
      const std::string s( ws.begin(), ws.end() );
  
      std::cout&lt;&lt;"std::string =     "&lt;&lt;s&lt;&lt;std::endl;
      std::wcout&lt;&lt;"std::wstring =    "&lt;&lt;ws&lt;&lt;std::endl;
  
      std::stringstream ss;
      ss &lt;&lt; ws.c_str();
      std::cout&lt;&lt;"std::stringstream =     "&lt;&lt;ss.str()&lt;&lt;std::endl;
  }
  </code></pre>
  
  <p>The output is :</p>
  
  <pre><code>std::string =     Hello
  std::wstring =    Hello
  std::stringstream =     0x860283c
  </code></pre>
  
  <p>therefore the stringstream can not be used to convert wstring into string.</p>