Hi all
Does somebody have a tutorial on colors in c++ (Linux). I searched the forum multiple times, but all i can find are tutorials for win32
Thx in advance
Hi all
Does somebody have a tutorial on colors in c++ (Linux). I searched the forum multiple times, but all i can find are tutorials for win32
Thx in advance
http://www.linuxgazette.com/issue65/padala.html
hope this helps
"Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
-- Cowper
Operating Systems=Slackware Linux 9.1,Windows 98/Xp
Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)
You may teach a person from now until doom's day, but that person will only know what he learns himself.
Now I know what doesn't work.
A problem is understood by solving it, not by pondering it.
For a bit of humor check out xkcd web comic http://xkcd.com/235/
thx
do you have one for C++ or is it threaded the same way?
It works the same in C++, just convert the printf() calls to cout<< calls.
Make sure you read "The Catch" section, then read up on NCURSES.
gg
i converted the printf to cout <<
but now i dont see any colors
[color.cpp]
[colors.h]Code:/* Program by Da Boost */ #include <iostream.h> #include "colors.h" void Color(int, int, int); int main() { Color(Bright, Black, White); cout << "HELLO WORLD!!!" << endl; Color(Reset, White, Black); return 0; } void Color ( int Attr, int Fgc, int Bgc )$ { cout << "0x1B[" << Attr << ";" << Fgc + 30 << ";" << Bgc + 40 << "m"; }
[ouput]Code:// colors.h // This file defines color codes used in Linux // By Da Boost // Attributes #define Reset 0 #define Bright 1 #define Dim 2 #define Underline 3 #define Blink 5 #define Reverse 7 #define Hidden 8 // Colors$ #define Black 0 #define Red 1 #define Green 2 #define Yellow 3 #define Blue 4 #define Magenta 5 #define Cyan 6 #define White 7
0x1B[1;30;47mHELLO WORLD!!!
0x1B[0;37;40m
how can i fix this ?
>> i converted the printf to cout <<
No, you didn't.
C
printf("%s", command);
C++
cout << command;
gg
> cout << "0x1B["
Should be wriiten as
Code:cout << "\x1B["
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
thx all
but isn't there an alternative for the sprintf() ?
what does it do ?
thx in advance
sprintf just writes something to a string. It's for synthesizing strings from fragments of data and constants, etc...
edit: It's quite useful for writing clean output statements.