I have been using turbo c++ from quite long time, I have noticed that there are by default 16 colours(0-15) but I know that there is a way to make your own custom background and text colours, does anybody know how to do it...?
-
Ditch Turbo C++ and use some post-first-standard C++ compiler, like g++/clang++ etc, with a text editor or IDE. – vsoftco May 23 '15 at 20:25
-
3You guys just don't appreciate time-travel. – Martin James May 23 '15 at 20:28
-
This really is unrelated to the compiler version. It's about a particular graphics API... knowing more about the environment is necessary. Is this DOS on a PC-AT compatible? – Ben Voigt May 23 '15 at 20:49
-
@BenVoigt I think it is DOS – Angad Singh May 23 '15 at 20:56
-
@Martin James ,@vsoftco, There is an extension for graphics.h to be used with codeblocks, so turbo c++ is an ancient relic, but library isn't...! – Angad Singh May 23 '15 at 20:56
3 Answers
In text mode there truly are only 16 colors each for foreground and background, because foreground and background color are each specified by a four bit bitfield, so that the total is 8 bits, and it's stored in video RAM just like that and interpreted by the GPU (in VESA emulation mode).
To get additional colors, you'll have to switch to a graphics mode. You may want to search for "Turbo C++ graphic mode", which finds many tutorials.

- 277,958
- 43
- 419
- 720
In Turbo C++ you can use textcolor( )
textbackground( )
to set whatever color you want out of the color palette. Browse the Help menu.
// MSDOS Turbo C++ code
#include <conio.h>
int main()
{
textbackground(BLUE); //set the background color
textcolor(WHITE);
clrscr();
gotoxy(30,12);
cputs("Hello");
return 0;
}

- 8,490
- 3
- 24
- 28
-
That doesn't solve the problem, I know that there are 16 macros/enumerator for default colour,but I want more than 16 colours. – Angad Singh May 30 '15 at 21:07
You can use more colors using graphics by using setrgbpalette()
function... To know more about this function see setrgbpalette
in the help index (or here) and compile the given example of setrgbpalette
. You can create more custom colors, but only 16 colors can be used at a time.

- 5,306
- 6
- 27
- 47