c++ console colors

I just wanted to ask is it possible to use colors when program is running in console? Thanks!
Yes, you can do it using external libraries (as curses) If you are working on Windows, you can also use Windows API
Here. I have some code that my friend taught me that uses the system ("COLOR "); statement. You can find different colors by opening up a cmd, and typing: color tree.
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main()
{
    system ("COLOR e4");
    cout << "\n\n\n\t\t\t\tHELLO!\n\n";
    system ("PAUSE");
    return 0;
}
              

Hope this helps!
Last edited on
Aaiiiiiiieeeeee!

If on Windows, use
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <limits>
#include <windows.h>

using namespace std;

int main()
{
    SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0xE4 );
    cout << "\n\n\n\t\t\t\tHELLO!\n\n";

    SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), 0x07 );
    cout << "Press ENTER to quit." << flush;
    cin.ignore( numeric_limits <streamsize> ::max(), '\n' );

    return 0;
}

Let me know if you are on 'nix.
Topic archived. No new replies allowed.