C++ underline output

user2326844 picture user2326844 · Jun 18, 2014 · Viewed 26k times · Source

How can I underline a text which is supposed to be an output of a c++ code?

Somewhere in the web I saw this:

cout<<underline<<"This is the text which is going to be underlined.";

But, for me this "underline" is not working. Any idea is very welcome.

Answer

r3mainer picture r3mainer · Jun 18, 2014

Are you outputting to an ANSI terminal? If so, the following escape sequence should work:

#define underline "\033[4m"

More information on ANSI escape sequences is available here.

Note: To turn underlining off again, use "\033[0m".