But, when I print them back out to cout, it prints the escape character instead of using the character to format the text(ie it prints "\033[0;37m", instead of changing the color of the text to gray. If I print the same escape character using a string constant(manually), it formats the text.
\ is an escape character in C++ string literals. \033 stands for ascii 27, so that's the character you have to use in the file - literally writing \033 won't do.