Adding Color Text to C++ Console Application
2 posters
:: C Languages :: C++ :: Help!
Page 1 of 1
Adding Color Text to C++ Console Application
Hello!
I was wondering how one would go about adding colored text to a C console application. I know it can be done because I found this.
On that website, I found this image, which proves that it can be done.:
(Obviously, this screenshot was not taken by me.)
I tried to compile the following code, without modifying it in any way, but it didn't work. I checked for basic syntax errors, of which I found none. Not only that, but I did not know what any of the errors meant.
I was wondering how one would go about adding colored text to a C console application. I know it can be done because I found this.
On that website, I found this image, which proves that it can be done.:
(Obviously, this screenshot was not taken by me.)
I tried to compile the following code, without modifying it in any way, but it didn't work. I checked for basic syntax errors, of which I found none. Not only that, but I did not know what any of the errors meant.
- Code:
#include "Console.h"
namespace con = JadedHoboConsole;
int main()
{
using std::cout;
using std::endl;
cout << "I like " << con::fg_green << "green" << con::fg_white << " eggs and ham." << endl;
}
Re: Adding Color Text to C++ Console Application
That code does not work because you don't have the Console.h header file. Now there are multiple ways to add color to a C++ console app and if you really want to use the above stuff then I suggest looking for the header file somewhere. xD
Here are some ways I know how to do so however at varying difficulty.(Stupid WinAPI:////).
All of the below require this header file : Windows.h and correspondingly this line of code :
Here is the first method...
Here are the color numbers, now I don't use this function often so you may have to experiment a bit in case my memory is wrong. :-/(And I am too lazy to test it out myself. xDDD)
0 = Black
1 = Blue
2 = Green
3 = Light blue?
4 = Red
5 = Purple
6 = Yellow?
7 = White
8 = Gray
9 = Another blue I think....
Then I think it switches to letters...
A = Light Green
B = Light Aqua
C = Some sort of red...I think...
D = Light Purple
E = Light Yellow
F = I honestly forget. xD
This wil make the background black and the text red.
EDIT :
LAWL I found it on Code Project and I guess you did too. xD Good thing I had an account. c:
Here is the header file if you wish to have it and use your method. :-)
http://tinyurl.com/86dyoqa
lulZ They use the really hard WinAPI method. LAWL I did not want to put that hear since I barely even get it but yeah.... XD
Here are some ways I know how to do so however at varying difficulty.(Stupid WinAPI:////).
All of the below require this header file : Windows.h and correspondingly this line of code :
- Code:
#include <Windows.h>
Here is the first method...
- Code:
system("COLOR );
Here are the color numbers, now I don't use this function often so you may have to experiment a bit in case my memory is wrong. :-/(And I am too lazy to test it out myself. xDDD)
0 = Black
1 = Blue
2 = Green
3 = Light blue?
4 = Red
5 = Purple
6 = Yellow?
7 = White
8 = Gray
9 = Another blue I think....
Then I think it switches to letters...
A = Light Green
B = Light Aqua
C = Some sort of red...I think...
D = Light Purple
E = Light Yellow
F = I honestly forget. xD
This wil make the background black and the text red.
- Code:
system("COLOR 04");
- Code:
#include <Windows.h>
#include <iostream>
int main(){
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
for(int colorCode = 1; colorCode < 255; colorCode++){
SetConsoleTextAttribute(hConsole, colorCode);
std::cout <<"LAWLALWALWALAWLLWA\n";
}
std::cin.get();
return 0;
}
EDIT :
LAWL I found it on Code Project and I guess you did too. xD Good thing I had an account. c:
Here is the header file if you wish to have it and use your method. :-)
- Code:
///@note I did not under no circumstances write this file, and all credit goes to the respective authors of the file.
http://tinyurl.com/86dyoqa
lulZ They use the really hard WinAPI method. LAWL I did not want to put that hear since I barely even get it but yeah.... XD
Last edited by legolizard on Mon Jan 02, 2012 5:35 pm; edited 2 times in total (Reason for editing : Replaced Download URL http://www.mediafire.com/?72jrt3a2kpx76kd)
legolizard- Posts : 137
Join date : 2011-08-01
Location : On planet Char.
Re: Adding Color Text to C++ Console Application
No problem mate. Which method did you end up using?
legolizard- Posts : 137
Join date : 2011-08-01
Location : On planet Char.
Re: Adding Color Text to C++ Console Application
Right now, I have not used this thread for anything, but I will be in the near future.legolizard wrote:No problem mate. Which method did you end up using?
Re: Adding Color Text to C++ Console Application
To answer your question about which method I ended up using lego, I ended up using your method because I could not get Console.h to work, so I compiled this...legolizard wrote:No problem mate. Which method did you end up using?
...and got this.:legolizard wrote:
- Code:
#include <Windows.h>
#include <iostream>
int main(){
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
for(int colorCode = 1; colorCode < 255; colorCode++){
SetConsoleTextAttribute(hConsole, colorCode);
std::cout <<"LAWLALWALWALAWLLWA\n";
}
std::cin.get();
return 0;
}
I know that this image doesn't show the entire screen, so here is an image of the entire screen.
Thanks again lego!
Re: Adding Color Text to C++ Console Application
Yup anytime. But if you want me to show you how to use the header file I would be glad to. May also give me impetus to make another tutorial haha.
legolizard- Posts : 137
Join date : 2011-08-01
Location : On planet Char.
Re: Adding Color Text to C++ Console Application
You should do something more basic before you make a tutorial on this.legolizard wrote:Yup anytime. But if you want me to show you how to use the header file I would be glad to. May also give me impetus to make another tutorial haha.
Re: Adding Color Text to C++ Console Application
Ah okay, but would you still like to know how to use header files? 0o0
legolizard- Posts : 137
Join date : 2011-08-01
Location : On planet Char.
Re: Adding Color Text to C++ Console Application
Yes, but not right now.legolizard wrote:Ah okay, but would you still like to know how to use header files? 0o0
Similar topics
» Admin posts different color
» Changing title and username color.
» Mobile Application Development Forum
» Changing title and username color.
» Mobile Application Development Forum
:: C Languages :: C++ :: Help!
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|