Search code examples
c++cdosturbo-c

Easiest way to colour text in C/C++ DOS?


I made a basic snake game in a DOS enviroment using turbo C++ 3.0, and I'm quite a rookie myself. I've been looking for a while for a very simple and perhaps rudimentary way of making text of different colors in a DOS window. I'm not looking for complicated ways of coloring text. Most programs I'm writing are extremely simple and basic, and a complicated code to colour text that's larger than the program itself would just be confusing and ineffective.

My question is, what is the simplest way of coloring text in a DOS console in BOTH language, C and C++?


Solution

  • You can use Turbo C/C++'s-only (that is, non-standard) functions textcolor(), textbackground() and textattr() together with cprintf(), cputs() and putch(). See their description in the IDE's help, they're all in conio.h.