|
-
Sep 3rd, 2001, 12:04 PM
#1
Thread Starter
Addicted Member
colors in console?
Anyone knows how to write something in colors in console applications?
For example, how do I write "Hello" in red?
-
Sep 3rd, 2001, 12:11 PM
#2
If you're using Borland, try this:
Code:
#include <conio.h>
#include <stdio.h>
int main()
{
textcolor(15);
printf("Hello World!\n");
return 0;
}
If you're using Visual C++, try this:
Code:
#include <windows.h>
#include <stdio.h>
int main()
{
// Set color to yellow
SetConsoleTextAttribute(GetStdHandle(STD_OUT), 14);
printf("Hello World!\n");
return 0;
}
-
Sep 3rd, 2001, 02:31 PM
#3
Frenzied Member
Here is some more info for the SetConsoleTextAttribute second parameter
wAttributes
Specifies the foreground and background color attributes. Any combination of the following values can be specified: FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY. For example, the following combination of values produces white text on a black background:
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|