title: Unicode and std::string in C++
body: <p>If I write a random string to file in C++ consisting of some unicode characters, I am told by my text editor that I have not created a valid UTF-8 file.</p>
  
  <pre><code>// Code example
  const std::string charset = "abcdefgàèíüŷÀ";
  file &lt;&lt; random_string(charset); // using std::fstream
  </code></pre>
  
  <p>What can I do to solve this? Do I have to do lots of additional manual encoding? The way I understand it, std::string does not care about the encoding, only the bytes, so when I pass it a unicode string and write it to file, surely that file should contain the same bytes and be recognized as a UTF-8 encoded file?</p>