in a consoel app (dos) i know you can change the color by using something like font[1] and 1 stands for red or something wut do i use for changing text color
Printable View
in a consoel app (dos) i know you can change the color by using something like font[1] and 1 stands for red or something wut do i use for changing text color
does no one know!?!??!?!?!!?!
I always use <conio.h> and their textcolor, although it may not work for you...
You have to do a clrscr(); afterwards to have the changes take effect. That means that only 1 color on the screen at a time, there is a way to do it with more than 1 color, I am sure if you keep posting someone will give you the code.Code:textcolor(RED);
textbackground(BLACK);
clrscr();
Anyhow, look through conio.h for all of the colors that you can use, and I think you must always type them in capitals.
RED, BLUE, GREEN, YELLOW, LIGHTCYAN, stuff like that, check out conio.h
Hope that helps. And if I am way off topic (as usual), just ignore me (as usual ;) )
This has been asked a couple of times, I recommend checking the search feature located above on the right.Code: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( void )
{
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, FOREGROUND_RED);
printf("WWWWOOOOO MY TEXT IS RED WWOOOOO!!");
return 0;
}
--------------------------------------------------------------------------------
Traveller's example works for all C/C++ compilers, Kyoto's example works for Dev-C++ (and maybe gcc compilers to)
Actually the standard output methods don't work right with textcolor()/textbackground(). That's why there was cprintf() or similar in conio.h, if I remember correct(I don't have conio.h in my current compiler). With cprintf() you need the Windows's CR\LF for newline.Quote:
Originally posted by Kyoto Oshiro
You have to do a clrscr(); afterwards to have the changes take effect. That means that only 1 color on the screen at a time, there is a way to do it with more than 1 color, I am sure if you keep posting someone will give you the code.
Works only if it supports WinAPI. DJGPP's gcc supports that but gnu gcc doesn't.Quote:
Originally posted by Quantrizi
Traveller's example works for all C/C++ compilers, Kyoto's example works for Dev-C++ (and maybe gcc compilers to)
Well, I am pretty sure only gcc compilers (like MingW, Cygin (or something like that)) have conio.h because msvc++ doesn't.
[edit]If you use textcolor() and/or textbackground(), you have to include conio.o[/edit]
i use dev c++ 4. but it doesnt have the header file conio.o can someone uplaod it to a post so i can download it?
conio.o is something u have to link to. conio.h is the header file. conio.o is in the lib folder
raimo, actually you can do cout<< and it display text color...
That always gets the job done. You can't use standard cout<< and such for the way Traveller showed.Code:#include <iostream.h>
#include <conio.h>
int main()
{
textcolor(LIGHTBLUE);
textbackground(BLACK);
clrscr();
cout<< "This will be Light Blue on a Black background.\n";
return(0);
}
duh! i wasnt born yesterday. i did it right its jsut i dont have that lib file for some reason caus ei tried to compile it and it said it didnt have the file
oh its conio.h on earlier posts u said it was conio.o
sorry about that....
i compiled it, btu isntea dof lookign at a dos mode window (im in a console app)
a windows window popped up saying
on the window bar it said compiler lnker out and input
what does this meanQuote:
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b2b):comput~1. cpp: undefined reference to `textbackground'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b33):comput~1. cpp: undefined reference to `clrscr'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b3d):comput~1. cpp: undefined reference to `textcolor'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b4a):comput~1. cpp: undefined reference to `textbackground'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b52):comput~1. cpp: undefined reference to `clrscr'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b81):comput~1. cpp: undefined reference to `textcolor'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b8e):comput~1. cpp: undefined reference to `textbackground'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3b96):comput~1. cpp: undefined reference to `clrscr'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3bc5):comput~1. cpp: undefined reference to `textcolor'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3bd2):comput~1. cpp: undefined reference to `textbackground'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3bda):comput~1. cpp: undefined reference to `clrscr'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c09):comput~1. cpp: undefined reference to `textcolor'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c16):comput~1. cpp: undefined reference to `textbackground'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c1e):comput~1. cpp: undefined reference to `clrscr'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c4d):comput~1. cpp: undefined reference to `textcolor'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c5a):comput~1. cpp: undefined reference to `textbackground'
C:\WINDOWS\TEMP\ccziGggb.o(.text+0x3c62):comput~1. cpp: undefined reference to `clrscr'
Ok, I ain't accusing u of being a n00b, but this is a step-by-step process:
1. Include conio.h
2. Right click on the project name
3. Go to project options
4. Go to "Further object files or linker options"
5. Type this in: C:\Dev-C++\Lib\conio.o
6. Click ok
C:\Dev-C++\ may not the directory, but you know what to do if it ain't