General Question

Waffle's avatar

How can I write a C++ program that outputs different colored characters?

Asked by Waffle (248points) January 30th, 2009

If I’m witting a program in C++ that will be compiled with CodeBlocks and run as a console application with cmd.exe, is there any way the program can output (probably using cout) in a different font color. This is going to be using in a console based game.

Observing members: 0 Composing members: 0

2 Answers

Grisson's avatar

Usually you use ANSI codes for colors. This will assume that the console is an ANSI terminal or ANSI terminal emulator.
ANSI codes usually look like escape sequences. e.g. <ESC>[32m (set to green).

If you are coding under unix, you can look at the termcaps file to determine what to output for whatever terminal you are using.

Then again, you could always go with a GUI or web app, and use fonts and colors. But that’s getting away from your question.

I may be wrong, but I believe the cmd window supports ANSI.

Answer this question




to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
Knowledge Networking @ Fluther