C++ setbkcolor() - Define the Background Color

- July 12, 2018
setbkcolor in cpp


In C++, the setbkcolor() is used to define background color of the screen. You can set any background color according to your need by using this function.

Syntax of setbkcolor() Function

The general syntax of this function is as follows:

setbkcolor(co);
Where:
co It represents color. It can be a "int" type value or variable. Its value is from 0 to 15 for VGA screen. It may also be a numerical constant identifier such as BLUE, RED and GREEN etc.


Example of setbkcolor() Function

The following C++ program displays the word "Welcome" in different colors and also with different background colors.

#include<iostream>
#include<canio>
#include<graphics>
using namespace std;
  main()
   {
      int driver, mode, co;
      driver = DETECT;
      initgraph (&driver, &mode, " ");
      cleardevice();
      for (co = 0; c<= 15; co++)
      {
         setbkcolor(co);
         setbkcolor (co + 1);
         settextstyle (0, 0, 2);
         outtextxy (100, 10+co*20, "Welcome");
         outtextxy(450, 400, "Press any key");
         getch();
      }
  closegraph();
}

Leave your reply.
EmoticonEmoticon