Changing of printf()'s text colour in c [Solved/Closed]

Report
-
Posts
4264
Registration date
Thursday August 19, 2010
Status
Moderator
Last seen
August 3, 2016
-
Hello,

i want to change the color of the result text of printf().how can I do so?
(i want to hide it!)
i would appreciate your help.

2 replies

Posts
4264
Registration date
Thursday August 19, 2010
Status
Moderator
Last seen
August 3, 2016
984
Greetings,

What compilator do you use (Codeblocks, Codelite....)?
i use Microsoft visual studio.
tnx... but I don't want to change all the out put.just some of them.
Posts
4264
Registration date
Thursday August 19, 2010
Status
Moderator
Last seen
August 3, 2016
984
Is there any option look like changing the color of printf?
well I didn't see of any.they all change the result completely, I saw somewhere writing:
(if the what i've printed and I want to hide now is '<')

gotoxy(x,y-1);
textcolor(0):
printf("<");
tnx I found the answer.hear is a code I found :

#include <iostream>
#include <windows.h>

using namespace std;

int main() {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

// you can loop x higher to see more color choices
for(int x = 1; x < 255; x++) {

// pick the colorattribute x you want
SetConsoleTextAttribute(hConsole, x);
cout << x << "Colorful text!" << endl;
}

cin.get(); // wait
return 0;
}
Posts
4264
Registration date
Thursday August 19, 2010
Status
Moderator
Last seen
August 3, 2016
984
Thank you for your feedback GH. Happy for you ;-)