'Enable the writing of ANSI escape codes on a file?
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.
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:
cout << "\033[31m" << "Red string";
and it works. But if I want to write it on a .rtf file for example:
#include <iostream>
#include <fstream>
using namespace std;
ofstream os( "this_file.rtf" );
os << "\033[31m" << "Red string";
os.close();
it doesn't work and output in the file something like:
#[31mRed string
is there a way to enable the writing of an ANSI escape code on an output file like that one? Thanks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|