making text bold and colored in console program

Hi

Please don't forget that I'm a beginner. So, please don't making things more complicate for me. :)

I have this code and the program is functional. But I want the bold lines in the following code to be bold and blue. How do I do this? Is this possible? Please guide me. Thanks a lot.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include <iostream>
# include <cmath>
#include <stdlib.h>

using namespace std;
int main ()

{
    float a, b, c, R1, R2; //variables and constants used
    cout << "Enter a, b, c of the equation ax^2 + bx + c = 0" << endl;
    cout << "Enter a = ";
    cin >> a;
    cout << "Enter b = ";
    cin >> b;
    cout << "Enter c = ";
    cin >> c;
    float D = b*b - 4*a*c;
    if (D >= 0)
    {
        cout << "R1 is = " << ( -b + sqrt(D) )/( 2*a ) << endl;
        cout << "R2 is = " << ( -b - sqrt(D) )/( 2*a ) << endl;
    }
    else
    {
        cout << "no real roots exist" << endl;
    }
    
    system("PAUSE");
}
This depends on which system you are on. Windows I am not sure how it does it anymore, since it doesn't want to rely on the console that much. I don't know if its a ANSI or VT-xxx terminal anymore.

If you are on Linux there are several console libraries to help with that stuff. nCurses I believe is what it is called. I don't know if it ports to windows without something like one of the linux emulators out there.

Borland compilers, and Open Watcom compilers might have libraries for doing this in console which were easy to use.

I don't know how complex you were talking. If I were to be careful I would have to research based on the platform I was using.
Thanks, Azagaros.

I'm using Dev-C++ on Win XP Pro. Is there any help?
Dev-C++ is the wxWidgets base tool, much like Code::Blocks or CodeLite. It doesn't tell me which compiler you are using behind it.

If it is Microsofts compiler I doubt it has the libs for that kind of stuff anymore.

If it is GCC of some form. nCurses may be available but not one hundred percent sure. It also may need something like MinGW to use it.

Borland and Open Watcom work with Code::Blocks and many of the old libraries for doing color consoles might be there since both still work on FreeDOS.

These are checking the documentation of the compilers to see what it has in its base libraries for doing these things.
Dev-C++ generally comes bungled with a version of MinGW. That said, I'd like to ask that you move away from Dev-C++, just because the bundled MinGW and the IDE alike are both ancient.

Now, as for text styling, I would indeed recommend pdcurses. If you don't already have that or another curses variant you can get it here:
http://pdcurses.sourceforge.net/

Best of luck!

-Albatross
Last edited on
thank you, I am not that versed in the window api and that is very simple.
Topic archived. No new replies allowed.