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
Printable View
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
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
Uh... That is the character 0x1B, not the string "0x1B".
> cout << "0x1B["
Should be wriiten as
Code:cout << "\x1B["
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.
thx all