I am writing a program in C. I want to change the text color and background color in the console. My sample program is -
#include
#include &
I Know, I am very late but, May be my answer can help someone. Basically it's very Simple. Here is my Code.
#include
#include
using namespace std;
int main()
{
HANDLE colors=GetStdHandle(STD_OUTPUT_HANDLE);
string text;
int k;
cout<<" Enter your Text : ";
getline(cin,text);
for(int i=0;i9 ? k=0 : k++;
if(k==0)
{
SetConsoleTextAttribute(colors,1);
}else
{
SetConsoleTextAttribute(colors,k);
}
cout<
OUTPUT
This Image will show you how it works
If you want the full tutorial please see my video here: How to change Text color in C++