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
uh, wheres the project name?
Instead, just click on Project in the menu bar, and do steps 2-6
the project tab thingy is greyed out
Let me guess....you didn't create a project?
hhm, ill recreate it, im using a .cpp file copied form a floppy disk that was on my other computer. so there is no project made. ill make a project and copy the code. all 800 somthing lines... ( thank god for copy and paste )
thanks for all your help!
Amen to that (now if we could use those for the 100x sentencesQuote:
Thank god for copy and paste
No prob with the help
****. it says it cant find the file conio.o on the linker thing. i gave it the correct address and EVERYTHING. thsi is the error under the lnker tab
Quote:
g++: C:\My: No such file or directory
g++: Documents\Daniels: No such file or directory
g++: Stuff\dev: No such file or directory
g++: c++: No such file or directory
g++: 4\Lib\conio.o: No such file or directory
g++: file path prefix `C:\MYDOCU~1\DANIEL~1\DEVC__~1\BIN\' never used
the header file ais at C:\My Documents\Daniels Stuff\dev c++ 4\Lib\conio.o
That's why...it has to be in the root (C: or whatever) directory.Quote:
Originally posted by Klinerr1
the header file ais at C:\My Documents\Daniels Stuff\dev c++ 4\Lib\conio.o
you mean right under c like c:\conio.o ?!?!?! i think its that the directories have spaces
no no no....I ment this: C:\Dev-C++\ where C: is the root directory, and Dev-C++ is where Dev-C++ is located at...so to link to the conio.o file, you'd put this: C:\Dev-C++\Lib\conio.o
i did! the program is in
C:\My Documents\Daniels Stuff\dev c++ 4\
i reinstaled it and put it in the defualt directory. its becuas ei put in spaces, now! it works!
....He could have just renamed the folders without spaces instead of reinstalling...
i tried that but it skrewed other **** up, cant xplain. reinstalign wa easier
What's the difference between clrscr() and system("CLS") ?? And what header file does the 1st one require?Quote:
Originally posted by Kyoto Oshiro
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 ;) )
Thanks :)
clrscr(); - // use conio.h
system ("cls"); // use stdlib.h
What's the difference??
beats me
I'm serious :)
You were right... it doesnt work for me :)Quote:
Originally posted by Kyoto Oshiro
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 ;) )
Errors:
F:\Projects\Temp\main.cpp
[Warning] In function `int main(int, char**)':
7 F:\Projects\Temp\main.cpp
`RED' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function
7 F:\Projects\Temp\main.cpp
`textcolor' undeclared (first use this function)
8 F:\Projects\Temp\main.cpp
`BLACK' undeclared (first use this function)
8 F:\Projects\Temp\main.cpp
`textbackground' undeclared (first use this function)
9 F:\Projects\Temp\main.cpp
`clrscr' undeclared (first use this function)
F:\Projects\Temp\Makefile.win
[Build Error] [main.o] Error 1
if u r using dev c++4 u gotta go to project>project options>add header file> find conio.o its under c:\dev-c++\libs\ by defualt
clrscr(); // works with the screen actually, I thinkQuote:
Originally posted by Ruski
What's the difference??
system ("cls"); // this just send a command to the dos shell to clear the screen
How come not #include <conio.h> just like iostream and others? :confused:Quote:
Originally posted by Klinerr1
if u r using dev c++4 u gotta go to project>project options>add header file> find conio.o its under c:\dev-c++\libs\ by defualt
i use devc++ 4 and clrscr(); works for me
It works for you because you include the conio.o that DEV people port it to use with Dev C++.Quote:
Originally posted by Klinerr1
i use devc++ 4 and clrscr(); works for me
I tried using textcolor() and textbackground() but there were problems. I did the following:Attached is a screenshot of the results. Can someone help me?Code:#include <iostream.h>
#include <conio.h>
void main()
{
textcolor(BLUE);
textbackground(RED);
clrscr();
cout << "This is a test...";
}
no u didnt. u gotta go to project>project optins> include file header its conio.o under devc++\lib i think thats your problemc ause i had that problem before
Thanks :) I'll check that out :)