...

View Full Version : Text Color C++



daniel_g
06-15-2007, 01:04 AM
I'm trying to add color to some text in my application, but I'm getting a nasty error:


#include <windows.h>
#include <iostream>
#include <cstdlib>
#include <conio.h>
#include <stdio.h>
#include <sstream>
using namespace std;


main(){
textcolor (YELLOW);
textbackground (BLUE);
cprintf ("Im yellow text on a nice blue background!");
}


error:


11 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `YELLOW' undeclared (first use this function)
11 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `textcolor' undeclared (first use this function)
12 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `BLUE' undeclared (first use this function)
12 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `textbackground' undeclared (first use this function)
13 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `cprintf' undeclared (first use this function)


Of course, I don't know what I'm doing. I just got the function from somewhere on the net, and it said the conio.h header should be used. Any ideas?

I'm using Dev-C++

EDIT: Never Mind, the problem is that conio.h is very limited in Dev-C++. Solution is to get a Borland C++ compiler.

ghell
06-18-2007, 07:56 PM
It seems that conio is compiler specific. It is best to avoid such things (I always make sure my code compiles on gcc/g++ with gnu or mingw)

UnTio
07-10-2007, 04:50 PM
Hello,
There is functions to work with text consoles in Win32. You can search them in the SDK from Microsoft or, I think in the next help file:
ftp://ftp.cs.virginia.edu/pub/lcc-win32/win32hlp.exe
You can, even, work with the mouse.
One function that you can employ is:

BOOL SetConsoleTextAttribute(

HANDLE hConsoleOutput, // handle of console screen buffer
WORD wAttributes // text and background colors
);

You'll need more than this.

daniel_g
07-10-2007, 05:08 PM
Thank you for the replies.
For that task I was specifically asked to work with Borland C++, and the conio library. I got confused because Dev-C++ did include conio.h, but it was very limited.
Dev-C++ does offer a 'conio2' library that includes all functions from Borland, and can be downloaded under updates, however, it can get a little bit tricky to make it work, so the easiest way to make it all work was to get a Borland specific compiler.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum