title: Enable the writing of ANSI escape codes on a file?
body: <p>I am struggling with a problem. I searched all around the web and StackOverflow website and found similar questions, but none of them provided me the answer I am searching.</p>
  <p>I am on a Linux system (Ubuntu) and basically want to know how to write an ANSI escape code in an output file. For example, if I want to write a red string on the terminal I do:</p>
  <pre><code>cout &lt;&lt; &quot;\033[31m&quot; &lt;&lt; &quot;Red string&quot;;
  </code></pre>
  <p>and it works. But if I want to write it on a .rtf file for example:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
  ofstream os( &quot;this_file.rtf&quot; );
  os &lt;&lt; &quot;\033[31m&quot; &lt;&lt; &quot;Red string&quot;;
  os.close();
  </code></pre>
  <p>it doesn't work and output in the file something like:</p>
  <pre><code>#[31mRed string
  </code></pre>
  <p>is there a way to enable the writing of an ANSI escape code on an output file like that one? Thanks.</p>