does anyone know how to make the output text a color in c++
for conio.h and windows.h all for BORLAND C++ 5.x ?
p.s.
how does everybody use those code tage on the board that allow tabbing ?
does anyone know how to make the output text a color in c++
for conio.h and windows.h all for BORLAND C++ 5.x ?
p.s.
how does everybody use those code tage on the board that allow tabbing ?
I know how to make the text a different color using the conio.h library. I am using the free compiler (Borland v 5.5.1) off their website, so it may be different for you. Anyhow, it is really quite simple, look at the code below.
----------------------------
#include <iostream.h>
#include <conio.h>
int main()
{
textcolor(CYAN);
textbackground(BLACK);
clrscr();
cout<< "This text color should be cyan.\n";
getch();
return(0);
}
----------------------------
Make sure to put the colors of the font/background in all capitals. Check the conio.h library for the full list of colors, it is pretty easy to spot.
Hope that helps.
Kyoto Oshiro
http://www.angelfire.com/realm2/horizon/files.html
Horizon Games
Can you do that repeatedly?
like
-or whatever?Code:backgroundcolor(BLACK); clrscr(); textcolor(RED); cout << "red"; textcolor(BLUE); cout << "blue";
[D3T]
Borland Turbo C++ 3.0 For Dos
*
do { war(); } while (nations == hostile);
... The best way to prevent wars is to have them.
You can change the color as much as you want, there is only one thing you have to remember. After each change of color (background or font) you need to use a clrscr() for the changes to take effect. And remember, to change the background it is textbackground(COLOR), not backgroundcolor(COLOR) as you had put.
Hope that helps.
Kyoto Oshiro
http://www.angelfire.com/realm2/horizon/files.html
Horizon Games
I'll post this so no-one dosent have to rererepost
You can change color without having to clear the screen if you use this, providing of course that you have windows.hCode:the colors can be mixed FOREGROUND_BLUE Text color contains blue. FOREGROUND_GREEN Text color contains green. FOREGROUND_RED Text color contains red. FOREGROUND_INTENSITY Text color is intensified. BACKGROUND_BLUE Background color contains blue. BACKGROUND_GREEN Background color contains green. BACKGROUND_RED Background color contains red. BACKGROUND_INTENSITY Background color is intensified #include <windows.h> #include <stdio.h> int main() { HANDLE hStdout; hStdout = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hStdout, FOREGROUND_RED); printf("WWWWOOOOO MY TEXT IS RED WWOOOOO!!"); return 0; }
All spelling mistakes, syntatical errors and stupid comments are intentional.
Heres a snippet from my console library.
Code:namespace Stoned_Console { // names are prepended with T for Text and B for Background. TRED for instance is red text. const unsigned short BLACK = 0; const unsigned short TRED = FOREGROUND_RED; const unsigned short BRED = BACKGROUND_RED; const unsigned short TGREEN = FOREGROUND_GREEN; const unsigned short BGREEN = BACKGROUND_GREEN; const unsigned short TBLUE = FOREGROUND_BLUE; const unsigned short BBLUE = BACKGROUND_BLUE; const unsigned short TCYAN = FOREGROUND_BLUE | FOREGROUND_GREEN; const unsigned short BCYAN = BACKGROUND_BLUE | BACKGROUND_GREEN; const unsigned short TMAGENTA = FOREGROUND_RED | FOREGROUND_BLUE; const unsigned short BMAGENTA = BACKGROUND_RED | BACKGROUND_BLUE; const unsigned short TYELLOW = FOREGROUND_RED | FOREGROUND_GREEN; const unsigned short BYELLOW = BACKGROUND_RED | BACKGROUND_GREEN; const unsigned short TDKGREY = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN; const unsigned short BDKGREY = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN; const unsigned short TLTGREY = FOREGROUND_INTENSITY; const unsigned short BLTGREY = BACKGROUND_INTENSITY; const unsigned short TLTRED = FOREGROUND_RED | FOREGROUND_INTENSITY; const unsigned short BLTRED = BACKGROUND_RED | BACKGROUND_INTENSITY; const unsigned short TLTGREEN = FOREGROUND_GREEN | FOREGROUND_INTENSITY; const unsigned short BLTGREEN = BACKGROUND_GREEN | BACKGROUND_INTENSITY; const unsigned short TLTBLUE = FOREGROUND_BLUE | FOREGROUND_INTENSITY; const unsigned short BLTBLUE = BACKGROUND_BLUE | BACKGROUND_INTENSITY; const unsigned short TLTCYAN = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY; const unsigned short BLTCYAN = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_INTENSITY; const unsigned short TLTMAGENTA = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; const unsigned short BLTMAGENTA = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY; const unsigned short TLTYELLOW = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; const unsigned short BLTYELLOW = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY; const unsigned short TWHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY; const unsigned short BWHITE = BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY; void colour(const unsigned short); // sets text and bkground colours }just bitwise or | the background colour and the text colour u want in the call.Code:void Stoned_Console::colour(const unsigned short colinfo) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colinfo); }
i.e.
colour(BWHITE|TYELLOW);
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Nevermind; you add green, blue and red.
I have a rabbit in my pants! Please be happy for me.