0

Alright, I have an assignment in which I have to use ANSI Escape Sequences to colorize output on the console. So "\033[0;31m" colorizes text after it to be red for example.

When I run the following:

cout << "\033[0;31mhello \033[0;37mworld";

It works as it is supposed to, with "hello" printing in red, and then going back to grey for "world"

Although, when I return this exact same string from a function and print it, it doesn't work, it just prints out the escape sequence. I am pulling my hair out here. I don't know if anyone would know anything about this. Any insight would be appreciated.

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by cjf90
0

It doesn't work on modern MS-Windows operating system. Those escept codes are intended for Win95 and MS-DOS Version 6.X and earlier which had ansi.sys device driver installed. ansi.sys has not been in use since probably Windows NT 4.0. See this Microsoft article.

0

It doesn't work on modern MS-Windows operating system. Those escept codes are intended for Win95 and MS-DOS Version 6.X and earlier which had ansi.sys device driver installed. ansi.sys has not been in use since probably Windows NT 4.0. See this Microsoft article.

I got it working... it was just because the escape character '/033' has to be one character instead of 4. Actually, ansi.sys and these codes still work with the command prompt on newer versions of windows: http://en.wikipedia.org/wiki/Ansi.sys (wikipedia, but none the less). I didn't have to do anything to make them work on my version of XP.

0

Yeah, it probably isn't included in Windows 7. The wikipedia article only says it is included up to Vista. The line that I posted above should work if you do have it. What I was having trouble with before is getting the codes to work in a string that was return from a function. But that was just because the escape character was being processed as 4 characters in that case. Thanks for your response.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.