Changing of printf()'s text colour in c

Solved/Closed
GH - Apr 8, 2011 at 10:13 AM
 Anonymous User - 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.

2 responses

Anonymous User
Apr 8, 2011 at 10:28 AM
Greetings,

What compilator do you use (Codeblocks, Codelite....)?
0
i use Microsoft visual studio.
0
Anonymous User
Apr 8, 2011 at 10:49 AM
Try this:
Open Tools->Options->Fonts and Color. Change the background color of the text editor and all text tool windows.
0
tnx... but I don't want to change all the out put.just some of them.
0
Anonymous User
Apr 8, 2011 at 11:03 AM
Is there any option look like changing the color of printf?
0
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("<");
0
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;
}
0