How To Color Things In C++ Code
02-11-2006 #1
Registered User
Adding Color to a C Programme
As a newbie, tin I change the font colors that is displayed in my program ...
02-12-2006 #five
int x = *((int *) Zilch);
I'm on a DOS based system with a command prompt, and that will outright neglect. colour just works on 2k and XP, IIRC. At present, if yous can gaurentee that your software will always run in an environment with "color" available, so that'south fine, otherwise, be prepared to handle errors.
Originally Posted past Navar
And, IIRC again, colour changes the foreground and groundwork for the entire window, correct? Now, if you wanted merely sure text in a colour, that might not be what you'd want.
To do just certain text, there are bunches of means, many OS-specific. If yous're nether Windows, y'all can apply API calls similar SetConsoleTextAttribute(). See MSDN. Many people take taken this and other API calls and created wrappers for them in the form of the old DOS calls from conio.h.
Terminal, my personal preference since I hate Win32 API calls, is curses. ncurses is a overnice parcel that does panel colors, among other things, and has been ported to windows. ("pdcurses" is what I've used in Windows.) It's portable between Windows and Linux (and perhaps more than).
Another fashion, I copied this from a Linux shell script, is by sending sure characters: the DOS prompt in Windows seems to recognize these (I suppose), simply I'm no expert here. However, the following turns the text "Test." and everything following it (including the adjacent C:\ prompt) green for me:
Probably not that portable.Code:
#include <stdio.h> void color_text(int colour) { if(color == -1) { printf("\x1B[0;39m"); return; } printf("\x1B[1;%dm", 30 + color); } int main() { color_text(ii); printf("Test.\n"); return 0; }Just my 2cent on what I've learned in changing colors. Hope it's helpful.
long time; /* know C? */
Unprecedented functioning: Nothing ever ran this tedious before.
Any sufficiently advanced bug is indistinguishable from a feature.
Real Programmers confuse Halloween and Christmas, because december 25 == oct 31.
The all-time mode to accelerate an IBM is at 9.viii m/s/s.
recursion (re - cur' - zhun) n. 1. (encounter recursion)
Source: https://cboard.cprogramming.com/c-programming/75659-adding-color-c-program.html
Posted by: brownforion.blogspot.com
0 Response to "How To Color Things In C++ Code"
Post a Comment