title: C++ - Replace special characters from file with non ascii characters
body: <p>I'm having a difficult time replacing some characters from my file with some diacritics from my mother tongue ; such as:</p>
  
  <pre><code>character_to_replace      replacement
      º                      ș
      ª                      Ș
      þ                      ț
      Þ                      Ț
  </code></pre>
  
  <p>I've found the Unicode for the character_to_replace but for some reason the file won't save to the expected output. I figured out it's something to do with the UTF-8 and unicode conversion. However i managed to print out the characters but only to the console when i try to write to the file it doesn't work. Here's my code:</p>
  
  <pre><code>void replace(string &amp;source, string to_replace, string replacement)
  {
      int found = 0;
      string auxiliar;
      auxiliar = source;
  
      while (found != string::npos)
      {
          found = auxiliar.find(to_replace);
  
          if (found != -1)
          {
              source.replace(found, 1, replacement);
              auxiliar = auxiliar.substr(found + to_replace.size());
          }
      }
  }
  
  int main()
  {
      cout &lt;&lt; endl;
  
      string line;
      ifstream file;
      ofstream send_line;
  
      send_line.open("out.txt");
      file.open("in.txt");
  
      while (!file.eof())
      {
          getline(file, line);
          replace(line, "\u00b0", "\u0219");
          replace(line, "\u00aa", "\u0218");
          replace(line, "\u00fe", "\u021b");
          replace(line, "\u00de", "\u021a");
          send_line &lt;&lt; line &lt;&lt; "\n";
      }
  
      file.close();
      send_line.close();
  }
  </code></pre>
  
  <p>Can you point me to the right direction where I may solve this ? Thank you.</p>