Replace unicode character in the string
If you're not worried about performance, you can replace all the manual work by using the &lt;regex&gt; facilities, which results in a considerable reduction of code to test and maintain.

#include &lt;regex&gt;

source = std::regex_replace(source, std::regex("€"), "\x80");


I would still keep it in a separate function to make it easy to change the implementation afterwards.