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

GH - Apr 8, 2011 at 10:13 AM - Latest reply: bionik 4523 Posts Thursday August 19, 2010Registration dateModeratorStatus August 3, 2016 Last seen
- Apr 10, 2011 at 07:48 AM
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.
See more 

8 replies

bionik 4523 Posts Thursday August 19, 2010Registration dateModeratorStatus August 3, 2016 Last seen - Apr 8, 2011 at 10:28 AM
0
Thank you
Greetings,

What compilator do you use (Codeblocks, Codelite....)?
0
Thank you
i use Microsoft visual studio.
tnx... but I don't want to change all the out put.just some of them.
bionik 4523 Posts Thursday August 19, 2010Registration dateModeratorStatus August 3, 2016 Last seen - Apr 8, 2011 at 11:03 AM
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;
}
bionik 4523 Posts Thursday August 19, 2010Registration dateModeratorStatus August 3, 2016 Last seen - Apr 10, 2011 at 07:48 AM
Thank you for your feedback GH. Happy for you ;-)